Results 1 to 4 of 4

Thread: QPainter error saving an image from a QGraphicsScene

  1. #1
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QPainter error saving an image from a QGraphicsScene

    Hi to all,
    I'm now compiling, without errors, a project using the latest Qt release (4.6) and created with the previous Qt 4.5.4 release (Windows).
    I'm coding my function using the example reported in "The Graphics View Framework" included in the Qt Help but now it isn't working. The message :

    Qt Code:
    1. QPainter::begin: Paint device returned engine == 0, type: 2
    To copy to clipboard, switch view to plain text mode 

    is appearing in my "Application Out"!!!

    Here is the code:

    Qt Code:
    1. void frmStats::creaFileHtml()
    2. {
    3. QString intestazioneFile =
    4. "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN "
    5. "http://www.w3.org/TR/html4/strict.dtd\">\n"
    6. "<html>\n"
    7. "<head>\n"
    8. "<meta content=\"text/html;"
    9. "charset=UTF-8\" http-equiv=\"content-type\">\n"
    10. "<title></title>\n"
    11. "</head>\n"
    12. "<body>\n";
    13.  
    14. QString chiusuraFile =
    15. "</body>\n"
    16. "</html>\n";
    17.  
    18. html.clear();
    19.  
    20. html += intestazioneFile;
    21.  
    22. QPixmap pixmap(endX, endY);
    23. QPainter painter(&pixmap);
    24. painter.setRenderHint(QPainter::Antialiasing);
    25. scene->render(&painter); // scene = new QGraphicsScene(QRect(0, 0, endX, endY), this);
    26. painter.end();
    27. pixmap.save(QDir::currentPath() + "/statistiche.png");
    28.  
    29. html += "<img src=\"" + QDir::currentPath() +
    30. "/statistiche.png\" ALIGN=\"center\">\n<br>\n";
    31.  
    32. html += chiusuraFile;
    33. // qDebug() << "HTML: " << html;
    34. }
    To copy to clipboard, switch view to plain text mode 

    What happens?

    Thanks!

  2. #2
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPainter error saving an image from a QGraphicsScene

    Sorry guys, it has been a my error!
    Solved.

  3. #3
    Join Date
    Jun 2006
    Location
    Colorado
    Posts
    12
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPainter error saving an image from a QGraphicsScene

    Could you explain how you solved your problem?

  4. #4
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPainter error saving an image from a QGraphicsScene

    Ok, but I'm warning you, it's quite strange. So I've commented the problem core lines:

    Qt Code:
    1. QPixmap pixmap(endX, endY);
    2. QPainter painter(&pixmap);
    3. // painter.setRenderHint(QPainter::Antialiasing);
    4. // scene->render(&painter);
    5. // painter.end();
    6. // pixmap.save(QDir::currentPath() + "/statistiche.png");
    To copy to clipboard, switch view to plain text mode 

    leaving only the QPainter declaration. That to find which instruction was the problem. And Taaa Daaa line by line I arrived at the end without having the error anymore!!!
    I don't know if it depends by the compiler (just a flicker) or my PC but now is working, that's my honest work, believe or not.

Similar Threads

  1. Problem saving JPG image
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 31st July 2009, 15:38
  2. Saving qwt plot as image
    By giusepped in forum Qwt
    Replies: 13
    Last Post: 14th July 2009, 07:39
  3. Saving QGraphicsScene with OpenGL to image
    By elbaschid in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2009, 20:32
  4. Saving a QPainter
    By xgoan in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2006, 13:36
  5. Saving already opened image ...
    By Godlike in forum Newbie
    Replies: 14
    Last Post: 28th March 2006, 21:17

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.