Search code examples
c++qthread

Making the main thread wait till all other Qthread finished


is there a way to force the main thread to wait until all threads created from it, will finish their job, before finishing the program. I mean:

int main(){
    QthreadClass a; // in cons' a thread is created and running
    QthreadClass b; // same as before

    *** wish to wait till both created thread finished their jobs ***

    return 0;

}


Solution

  • Well, what about:

    a.wait();
    b.wait();
    

    Or, you would rather start an event loop (as usually for Qt applications) that you quit when both of your threads end (QThread emits finished() and terminated() signals).