Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. App hangs in QPixmap::fromImage
Qt 6.12 LTS is out! See what's new in the release blog

App hangs in QPixmap::fromImage

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 6 Posters 17.4k Views 2 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.
  • M mpouchol

    @Christian-Ehrlicher the QImage to QPixmap conversion is only done in the main/UI thread.

    Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #6

    @mpouchol said in App hangs in QPixmap::fromImage:

    the QImage to QPixmap conversion is only done in the main/UI thread.

    This does not what I've suggested... go through your other threads and take a look what they're doing and if there's another one in this function.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    M 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @mpouchol said in App hangs in QPixmap::fromImage:

      the QImage to QPixmap conversion is only done in the main/UI thread.

      This does not what I've suggested... go through your other threads and take a look what they're doing and if there's another one in this function.

      M Offline
      M Offline
      mpouchol
      wrote on last edited by
      #7

      @Christian-Ehrlicher thanks for your suggestion. I'm not sure to understand what I should do.
      The convert_generic function is actually one of the function called by QPixmap::fromImage as you can see in the callstack attached to my question.
      The app is stuck in this function trying to acquire a semaphore.

      JonBJ 1 Reply Last reply
      0
      • M mpouchol

        @Christian-Ehrlicher thanks for your suggestion. I'm not sure to understand what I should do.
        The convert_generic function is actually one of the function called by QPixmap::fromImage as you can see in the callstack attached to my question.
        The app is stuck in this function trying to acquire a semaphore.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #8

        @mpouchol
        @Christian-Ehrlicher is asking you to grep all your code for every occurrence of a call to fromImage() and/or convertToFormat() to see whether you call it in more than one place.

        M 1 Reply Last reply
        0
        • JonBJ JonB

          @mpouchol
          @Christian-Ehrlicher is asking you to grep all your code for every occurrence of a call to fromImage() and/or convertToFormat() to see whether you call it in more than one place.

          M Offline
          M Offline
          mpouchol
          wrote on last edited by
          #9

          Thanks @JonB, I only use QPixmap::fromImage in the main thread. I do not call convertToFormat() directly, it's called in fromImage.

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mchinand
            wrote on last edited by
            #10

            Is your QImage good? Does saving the QImage to a file work? What is the QImage::Format of the image?

            M 1 Reply Last reply
            0
            • M mchinand

              Is your QImage good? Does saving the QImage to a file work? What is the QImage::Format of the image?

              M Offline
              M Offline
              mpouchol
              wrote on last edited by
              #11

              I not sure about the QImage, I will try to save it. It's mostly a temporary wrapper around the buffer data that's used to create a QPixmap. The format is QImage::Format_Grayscale8

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mchinand
                wrote on last edited by
                #12

                Also, does it sometimes work and sometimes hang or always hang? Are you possibly not getting a full frame of data from the camera? Each frame of data should be the same size (number of bytes), right?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mpouchol
                  wrote on last edited by
                  #13

                  It works most of the time and hangs randomly. It can take somewhere between a few seconds and a 1-2 hours to hang. Images are fetched from camera at around 60fps and each frame should be the same size. I suspect data gets corrupted somewhere but I was expecting a crash instead of an app freeze. It's a bit strange that it always hang at the same point.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    Again: it hangs on a mutex lock - nothing to do with the data. Take a look if this mutex is locked in another thread...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    M 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      Again: it hangs on a mutex lock - nothing to do with the data. Take a look if this mutex is locked in another thread...

                      M Offline
                      M Offline
                      mpouchol
                      wrote on last edited by
                      #15

                      @Christian-Ehrlicher the mutex is owned by Qt code inside QPixmap::fromImage
                      I don't use this function from other threads so I don't see what I did that caused it to stay locked.

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • M mpouchol

                        @Christian-Ehrlicher the mutex is owned by Qt code inside QPixmap::fromImage
                        I don't use this function from other threads so I don't see what I did that caused it to stay locked.

                        Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #16

                        @mpouchol said in App hangs in QPixmap::fromImage:

                        I don't use this function from other threads so I don't see what I did that caused it to stay locked.

                        I'm giving up... looks like it's too hard to look into the other threads while it is hanging to see if another thread is also using this mutex. So try to figure it out by your own.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        M 1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          @mpouchol said in App hangs in QPixmap::fromImage:

                          I don't use this function from other threads so I don't see what I did that caused it to stay locked.

                          I'm giving up... looks like it's too hard to look into the other threads while it is hanging to see if another thread is also using this mutex. So try to figure it out by your own.

                          M Offline
                          M Offline
                          mpouchol
                          wrote on last edited by
                          #17

                          @Christian-Ehrlicher said in App hangs in QPixmap::fromImage:

                          I'm giving up... looks like it's too hard to look into the other threads

                          I did that and that's not the case. Thanks for your help anyway.

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Online
                            Christian EhrlicherC Online
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #18

                            Ok, taking a deeper look into convert_generic() the qimage is converted with more than one thread. One of these subthreads hangs maybe due to a broken QImage. Look into your other threads to see which one is somewhere hanging inside convertSegment()

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            1
                            • M Offline
                              M Offline
                              mpouchol
                              wrote on last edited by
                              #19

                              I also had a look at the code inside convert_generic(). When the main thread is frozen I don't see other threads hanging in convertSegment which make me think that maybe one of the convertSegment threads has died silently and is not releasing the semaphore in convert_generic because I don't see visual studio raising exceptions in other threads.

                              1 Reply Last reply
                              0
                              • Christian EhrlicherC Online
                                Christian EhrlicherC Online
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #20

                                If you compile Qt by your own build a big try/catch block around convert_segment and simply catch all exceptions to see if there is one.
                                You can also create a helper thread which writes out the current qimage after a certain period of time when it was not canceled in between so you can inspect the qimage.

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

                                1 Reply Last reply
                                0
                                • Christian EhrlicherC Online
                                  Christian EhrlicherC Online
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #21

                                  Ah, see https://bugreports.qt.io/browse/QTBUG-90629 and https://bugreports.qt.io/browse/QTBUG-92188 even I don't see how this should affect windows.

                                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                  Visit the Qt Academy at https://academy.qt.io/catalog

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mpouchol
                                    wrote on last edited by
                                    #22

                                    @Christian-Ehrlicher said in App hangs in QPixmap::fromImage:

                                    https://bugreports.qt.io/browse/QTBUG-90629

                                    Indeed when looking at the stack trace it looks very similar to my case, almost the same function calls except for the low level semaphore things on linux.

                                    I think I may have to rebuild Qt and try your suggestion to wrap convert_segment around a try/catch block to have more detail.

                                    G 1 Reply Last reply
                                    0
                                    • M mpouchol

                                      @Christian-Ehrlicher said in App hangs in QPixmap::fromImage:

                                      https://bugreports.qt.io/browse/QTBUG-90629

                                      Indeed when looking at the stack trace it looks very similar to my case, almost the same function calls except for the low level semaphore things on linux.

                                      I think I may have to rebuild Qt and try your suggestion to wrap convert_segment around a try/catch block to have more detail.

                                      G Offline
                                      G Offline
                                      Gerald Lodron
                                      wrote on last edited by
                                      #23

                                      @mpouchol
                                      I updated my (working) software from 5.12.11 to 5.15.8 and have exactly the same problem, now the QPixmap::fromImage hangs. I did not debugged into qt but its defenitely in main thread and its my only and first call of it. It happens every time in my case, the image is a Format_Grayscale8 too

                                      is there a solution for it?

                                      G 1 Reply Last reply
                                      0
                                      • G Gerald Lodron

                                        @mpouchol
                                        I updated my (working) software from 5.12.11 to 5.15.8 and have exactly the same problem, now the QPixmap::fromImage hangs. I did not debugged into qt but its defenitely in main thread and its my only and first call of it. It happens every time in my case, the image is a Format_Grayscale8 too

                                        is there a solution for it?

                                        G Offline
                                        G Offline
                                        Gerald Lodron
                                        wrote on last edited by
                                        #24

                                        it really seems to have something to do with Format_Grayscale8, Format_RGB888 and QImage::Format_Mono works...

                                        1 Reply Last reply
                                        0
                                        • X Offline
                                          X Offline
                                          X-Hawk
                                          wrote on last edited by
                                          #25

                                          There must be some bug in QThreadPool cause QPixmap hangs.
                                          Set setExpiryTimeout to -1 may help, just a workaround, not bug fix.

                                          QThreadPool *threadPool = QThreadPool::globalInstance();
                                          if (threadPool) {
                                              threadPool->setExpiryTimeout(-1);
                                          }
                                          
                                          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
                                          • Unsolved