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. Update GUI from another object with 2 threads.
Forum Updated to NodeBB v4.3 + New Features

Update GUI from another object with 2 threads.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • jiapei100J Offline
    jiapei100J Offline
    jiapei100
    wrote on last edited by
    #1

    Hi, all:

    I've got a class which has a producer thread and a consumer thread. I would like the producer thread keeps producing the image data, and whenever the consumer thread is consuming the image data from the shared buffer, a signal will be sent out to the MainWindow GUI, for the purpose of redraw the image on GUI --- this signal/slot is of Qt::BlockingQueuedConnection for sure.

    However, I've got no idea why this doesn't work for me now (no image has ever been drawn on the MainWindow GUI). I guess it's probably because, the signal sent out to the MainWindow GUI is embedded inside the critical section -- the consumer thread lock the critical shared buffer using a mutex, and I sent out the signal from within this locked mutex section to the MainWindow GUI. Is this problematic? And is there a way out for my issue?

    Cheers
    Pei

    Welcome to Longer Vision
    https://www.longervision.com

    1 Reply Last reply
    0
    • jiapei100J Offline
      jiapei100J Offline
      jiapei100
      wrote on last edited by
      #2

      I know attached my code at "http://visionopen.com/questions/QtThreadExample.tar.gz":http://visionopen.com/questions/QtThreadExample.tar.gz . Can anybody help to explain what's wrong with my code? I do need your help please

      Cheers
      Pei

      Welcome to Longer Vision
      https://www.longervision.com

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        I'm not sure if this is part of your issue, but you're pushing and popping the same value from your buffer over and over again: m_iIdx never changes.

        Anyway, I notice you're using Boost threads with lots of sleep() and wait(). I'm not very familiar with this approach so I can't debug your thread logic, sorry.

        How big are your items, and how fast do you produce/consume them? If the items are small (or if they get consumed slowly), I suggest trying event-driven programming with Qt:

        Every time a consumer consumes an item, emit a consumed() signal

        When the producer receives the consumed() signal, produce a new item. Emit the item using a produced(item) signal.

        When the consumer receives the produced() signal, consume the item (go back to #1)

        This method is cleaner, you don't have to worry about deadlocks, and you can even implement the producer-consumer pattern using only 1 thread.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • jiapei100J Offline
          jiapei100J Offline
          jiapei100
          wrote on last edited by
          #4

          Hi, thanks JKSH.
          I solved that problem by removing the join().
          Consumer join() and producer join() blocks the main thread, namely MainWindow GUI.

          Thanks anyway.

          Welcome to Longer Vision
          https://www.longervision.com

          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