Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter converts a QImage to a QPixmap which isn't safe to use outside the GUI thread
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gcbsumid
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pkj__
      wrote on last edited by
      #2

      Is "this":https://bugreports.qt-project.org/browse/QTBUG-19886 related to your case?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gcbsumid
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved