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. How to (properly) check if ALL started QThread workers finished their tasks
Forum Update on Monday, May 27th 2025

How to (properly) check if ALL started QThread workers finished their tasks

Scheduled Pinned Locked Moved Solved General and Desktop
qthreadqthreadpoolmovetothreadworkerthread
5 Posts 3 Posters 2.2k Views
  • 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.
  • P Online
    P Online
    Pl45m4
    wrote on 21 Dec 2020, 18:30 last edited by
    #1

    I haven't used multithreading (especially QThreads) that often before and I'm wondering how to check if all started worker QThreads are finished() to continue processing the result from my threads in my GUI class.
    I came across QThreadPool::waitForDone() but as far as I understand, it only works with QRunnable?!
    In plain C++ I would just do something like std::thread->join() on all threads.

    Currently I'm using the classic "worker QObject + moveToThread()" approach with multiple workers /QThreads and I don't want to change it for now.

    Thanks in advance :)


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 Dec 2020, 18:35 last edited by
      #2

      Hi,

      AFAIR, the equivalent would be wait however it's blocking and likely not what you want.

      You should rather have a counter that you decrement each time a task is done and then do the rest once it reached zero.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply 21 Dec 2020, 18:43
      1
      • S SGaist
        21 Dec 2020, 18:35

        Hi,

        AFAIR, the equivalent would be wait however it's blocking and likely not what you want.

        You should rather have a counter that you decrement each time a task is done and then do the rest once it reached zero.

        P Online
        P Online
        Pl45m4
        wrote on 21 Dec 2020, 18:43 last edited by
        #3

        @SGaist said in How to (properly) check if ALL started QThread workers finished their tasks:

        AFAIR, the equivalent would be wait however it's blocking and likely not what you want.

        No :)

        You should rather have a counter that you decrement each time a task is done and then do the rest once it reached zero.

        A counter as member variable in my MainWindow class will work?!

        So I connect finished() to an additional slot which will decrease my member?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 21 Dec 2020, 18:49 last edited by
          #4

          That would be one way yes, if you spawn all your threads there.

          Depending on what you want to do you might want to consider modeling the execution using a state machine.

          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
          0
          • O Offline
            O Offline
            ollarch
            wrote on 22 Dec 2020, 10:49 last edited by
            #5

            Hi,

            You can connect the "finished()" signal to a slot and there check if all threads are not running. I assume that you have a list of threads.

            1 Reply Last reply
            1

            4/5

            21 Dec 2020, 18:49

            • Login

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