Results 1 to 4 of 4

Thread: QPainter::begin(): returned false error occasionally

  1. #1
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPainter::begin(): returned false error occasionally

    Hi,
    I am trying to print webview to a pdf page. At the loadFinished() signal of webview object, I do the following:
    Qt Code:
    1. void W_Test::loadFinished()
    2. {
    3. QString fileName = QFileDialog::getSaveFileName(this, tr("Choose existing file or type in new file name"),
    4. QString(), tr("Excel files (*.pdf)"));
    5. if(fileName.isEmpty()) return;
    6. QPrinter printer;
    7. printer.setOrientation(QPrinter::Landscape);
    8. printer.setPaperSize(QPrinter::A4);
    9. printer.setFullPage(true);
    10. printer.setOutputFormat(QPrinter::PdfFormat);
    11. printer.setOutputFileName(fileName);
    12. printer.setFromTo(1,1);
    13. webView->print(&printer);
    14. }
    To copy to clipboard, switch view to plain text mode 
    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. ??..

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPainter::begin(): returned false error occasionally

    Do you have painting code out side a paintEvent()?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainter::begin(): returned false error occasionally

    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...

  4. #4
    Join Date
    Apr 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPainter::begin(): returned false error occasionally

    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.

Similar Threads

  1. Replies: 4
    Last Post: 25th February 2011, 09:01
  2. Replies: 3
    Last Post: 23rd January 2011, 12:15
  3. QPainter::begin: Cannot paint on a null pixmap
    By sabeesh in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2010, 18:03
  4. Replies: 5
    Last Post: 20th October 2009, 07:18
  5. problem in QPainter::begin
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2009, 10:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.