PDA

View Full Version : QPainter::begin(): returned false error occasionally



pkj
13th March 2011, 14:17
Hi,
I am trying to print webview to a pdf page. At the loadFinished() signal of webview object, I do the following:

void W_Test::loadFinished()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Choose existing file or type in new file name"),
QString(), tr("Excel files (*.pdf)"));
if(fileName.isEmpty()) return;
QPrinter printer;
printer.setOrientation(QPrinter::Landscape);
printer.setPaperSize(QPrinter::A4);
printer.setFullPage(true);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
printer.setFromTo(1,1);
webView->print(&printer);
}
However i get QPainter::begin() : returned false message once in a while. Otherwise works like a charm...!!
My guesses are qwebview never emits loadFinished signal... but QPainter::begin() message shouldn't have come then. ??..

high_flyer
14th March 2011, 08:53
Do you have painting code out side a paintEvent()?

pkj
16th March 2011, 06:42
Sorry for replying so late..
No I don't have any painting code outside paintEvent()... I am not subclassing any class. I am using QWebView and trying to print it to pdf using the utility functions provided...

cera
24th April 2013, 19:10
I know this is an old thread, but in case it helps anyone else...

I was seeing the same problem - occasionally I would see "QPainter::begin() : returned false" when trying to print to a pdf file. In my case, I was generating the pdf file names from a database field, but sometimes the database field contained characters (such as " quotes) that are not valid within a file name. Then the pdf printer was unable to create a file with the invalid file name, and the 'begin' method failed. Perhaps this caused your issue also.