Displaying images outside the GUI thread (Boost thread)

  • Hi all,
    I am developing a C++ library realizing its interface by means of Qt, using VS2015. On the library side, 3 boost threads continously load images from 3 folders. I am trying to display these images in 3 different QLabel (or equivalent QWidgets), so the thread body consists of this functionality, in particular by exploiting the setPixmap method. Although the call to the function is protected by a boost mutex, I got exceptions probably due to threads synchronization. Looking for a solution, I already awared that the QPixmap widget is not "thread-safe" (non-reentrant). I also tried to use QGraphicsView but it in turn relies on QPixmap, thus I came across the same problem. So my question is: does an alternative to QPixmap exist to display images in Qt in a thread-safe manner?

  • Hi, welcome to the forum.
    All painting has to be done in the GUI thread.

  • Thanks for the anwer! By the way I solved using signal/slot: the "non-GUI" thread emits a signal instead of displaying the images and the called slot paints the QLabel inside the GUI thread!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Note that you can use QImage which is hardware independent for painting on from threads (see the mandelbrot example) however as @Wieland wrote the GUI itself can only be update from the main thread.

Log in to reply

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