Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.0
-
None
-
Gentoo Linux
Qt 4.5.3 (system)
Qt 4.6.3 + Qt 4.7.0 developer-build, + QtEmbedded 4.7.0
-
99bab571b4cb41362e891f1bb1e812119701c932, 8cc85123aee262f9ac061908aff0360247077075
Description
QPainter together with QPrinter leaves a lot of temporary files in /tmp with every printout. That is a problem for embedded devices, which have not such a large /tmp-partition. We are using 80 MByte as tmpfs, i.e. in RAM. After some printounts cups deactivates the printer because there is no space to copy the temporary files to /tmp.
What we are doing:
We are using QPrinter, QPainter and QGraphicsScene to printout scaled forms like
QPainter *printPainter = new QPainter;
QPrinter *printer = new QPrinter;
Form2Print *f2p = new Form2Print;
printPainter->begin(printer);
// some scene stuff to add widgets, not relevant...
printPainter->end();
If you debug, you will see, that before calling printPainter->end() with "lsof /tmp" you get a opened file, and after calling printPainter->end() you have a zombie, i.e. a non-closed but removed file with a "(deleted)" at the end. You will not see this files with ls.
I add an entire small project for you to demonstrate that.
What I found out is:
In all versions 4.4.2, 4.5.3, 4.6.2 and 4.7.0 it is the same.
In my opinion the problem is:
QPainter->end() calls d->engine->end() (which is an QPSPrintEngine)
There QPDFPrintEngine::end() will be called, which calls QPDFBaseEnginePrivate->closePrintDevice()
And there it happens: At the begin of the file "outDevice->close()" and "delete outDevice" are called, than there is some access to the file BUT at the end of the method there is a static call of QFile::remove(tempFile).
Sugestion: move "outDevice->close()" and "delete outDevice" call to the end of the file and in between call
QFile outfile = qobject_cast<QFile> (outDevice);
if (outfile)