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. Flushing events on mainthread from worker thread while main thread is blocked
Qt 6.11 is out! See what's new in the release blog

Flushing events on mainthread from worker thread while main thread is blocked

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 897 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.
  • J Offline
    J Offline
    jhoove64
    wrote on last edited by
    #1

    I have a scenario where a third-party library creates worker threads (not QThreads). The library calls a method on one of my objects to report progress. During this entire operation my main thread is blocked, but I need to update the progress bar on the main window.

    My progress function is therefore called from and executing in a worker thread. In the main thread, I have connected a signal in my class (containing the progress method) to a slot in the main window using a queued connection. The slots are not called until the control returns to the main GUI, which is when all of the work is done. What I need to do is after the worker thread emits the progress signal I need the worker thread to flushed the queued events on the main window (main thread). Calling sendPostedEvents() from the worker thread seems to have no effect. Any ideas anyone? Things go something like this:

    1. Main thread creates class A.
    2. Main thread has main window B.
    3. Main thread connects A::signal1 to B::slot1 using a queued connection.
    4. Third-party library function is called, main thread blocks.
    5. Worker thread emits A::signal1.
      ***It is at this point I need the main GUI to flush the queued signals (to get the GUI updated immediately), but neither sendPostedEvents() nor processEvents() work from the worker thread.

    Currently, all of the queued signals get processed once the main thread unblocks.

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

      Hi and welcome to devnet,

      Why is the main thread blocked ? Is it because of that 3rdparty library ? If so, why not handle it in a secondary 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
      1
      • J jhoove64

        I have a scenario where a third-party library creates worker threads (not QThreads). The library calls a method on one of my objects to report progress. During this entire operation my main thread is blocked, but I need to update the progress bar on the main window.

        My progress function is therefore called from and executing in a worker thread. In the main thread, I have connected a signal in my class (containing the progress method) to a slot in the main window using a queued connection. The slots are not called until the control returns to the main GUI, which is when all of the work is done. What I need to do is after the worker thread emits the progress signal I need the worker thread to flushed the queued events on the main window (main thread). Calling sendPostedEvents() from the worker thread seems to have no effect. Any ideas anyone? Things go something like this:

        1. Main thread creates class A.
        2. Main thread has main window B.
        3. Main thread connects A::signal1 to B::slot1 using a queued connection.
        4. Third-party library function is called, main thread blocks.
        5. Worker thread emits A::signal1.
          ***It is at this point I need the main GUI to flush the queued signals (to get the GUI updated immediately), but neither sendPostedEvents() nor processEvents() work from the worker thread.

        Currently, all of the queued signals get processed once the main thread unblocks.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        @jhoove64 said in Flushing events on mainthread from worker thread while main thread is blocked:

        Any ideas anyone?

        You have implemented your threading wrong? Show some code and we may discuss it.

        Currently, all of the queued signals get processed once the main thread unblocks.

        Any blocking operations should be offloaded from the main thread. Blocking the main thread, means no events are processed, means no updates to the UI are done and no UI input is accepted.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1

        • Login

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