QPrinter / QPainter error detection
Hi all
I am trying to figure out how to detect an error when printing a pdf using QPrinter and QPainter. Error detection is obvious when selecting a file that can't be opened for write as the QPainter::begin() fails. But what happens if the file opens for write, but the medium can't be flushed (not enough room). QPainter::end() returns true, as do any QPrinter calls like newpage. I'm expecting QPrinter will use a QFile internally, but there is no way to test the QFile::flush()?
Code parts:
Code:
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(filepath);
// This fails if file can't be opened for write
if (painter.begin(&printer) == false)
return false;
// any other call return true after this, even the end()
if (painter.end() == false)
return false;
// Even this returns no error
if (printer.
printerState() == QPrinter::Error) return false;
For reference, using Qt 4.8.7, testing this on Windows 7
Re: QPrinter / QPainter error detection
You could try using QPdfWriter with a manually opened QFile as the QIODevice.
Cheers,
_
Re: QPrinter / QPainter error detection
Using Qt 4.8.7 as mentioned above. I don't think QPdfWriter is an option for Qt 4.8?
Re: QPrinter / QPainter error detection
Oh, right, sorry, didn't see that.
Hmm, maybe use a QFileInfo on the filename and check if its size changes between pages?
Cheers,
_