Results 1 to 4 of 4

Thread: Advice needed regarding GUI and external thread cooperation

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Advice needed regarding GUI and external thread cooperation

    Hi,

    I need some advice regarding the following problem:
    I have a DLL that delivers images from a camera.
    This is being done in an external thread, and my application is being notified by a callback the image acquisition thread is calling.

    In that callback I have the ability to retrieve the new image buffer.
    And at that point I am facing my problem:
    If (while in the callback) I try to update my GUI (by using QLabel::setPixmap() with the new image, I get the debug message:
    "QPixmap: It is not safe to use pixmaps outside the GUI thread"
    which makes perfect sense, since indeed I am not in the GUI thread, but in the callback, which is in the image acquisition thread context.

    But how then, can I let my application know when it should refresh it self with the new image , from an external thread?

    Thanks in advance!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Advice needed regarding GUI and external thread cooperation

    I have found one solution:
    Looping in my GUI thread, and check for a flag set by the external thread.
    It works.

    But I wonder if there is a nicer solution?

    Thanks.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Advice needed regarding GUI and external thread cooperation

    Hi,

    Your thread grabs an image and there you can emit a signal to the main thread to let it display the image. Here you can emit a copy of image to ensure that there is no problem regarding memory cleanup when a new image arrives.
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Advice needed regarding GUI and external thread cooperation

    Hi Daniel, how is Mars? Still the "Red Planet"?

    As for your question - I would post an event to an object living in the main thread with the event object carrying a QImage acquired from the external source. Then you'll be able to transform it to QPixmap if required.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.