QPainter converts a QImage to a QPixmap which isn't safe to use outside the GUI thread



  • What I need to do is to print an image which I'm doing fine. When it's printing, I need to create a progress bar. So I followed this example:

    http://qt-project.org/wiki/Progress-bar

    However, I noticed that it didn't print it properly and it kept giving me an error saying QPixmap can't be used in a non-gui thread. This made no sense to me because I was printing a QImage which should be fine on a different thread.

    I looked into the QPaintEngine, specifically drawImage(), and it turns out that it converts the image to a QPixmap and it calls drawPixmap in qpaintengine_preview.cpp.

    So I'm not sure how to get around this.





  • I think the link above has the same title but not the same problem. It doesn't crash at all. It just displays "QPixmap: It is not safe to use pixmaps outside the GUI thread." message and continues on doing what it needs to (except for drawing the QImage).

    I can see that QPixmap isn't thread safe so I used a QImage instead which is.

    But when I make a drawImage(qImage) call in the different thread, the paintengine converts the QImage to a QPixmap and therefore won't work.


  • Lifetime Qt Champion

    Hi,

    I'm not sure I'm following you right, are you trying to do some painting outside the GUI thread ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.