How to (properly) check if ALL started QThread workers finished their tasks
-
I haven't used multithreading (especially
QThreads
) that often before and I'm wondering how to check if all started workerQThreads
arefinished()
to continue processing the result from my threads in my GUI class.
I came acrossQThreadPool::waitForDone()
but as far as I understand, it only works withQRunnable
?!
In plain C++ I would just do something likestd::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 :)
-
@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? -
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.