Do the main thread until all the other Qthreads end

Is there a way to make the main thread wait until all threads created from it finish their work before ending 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;

}

+7
source share
2 answers

Well, what about:

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

Or, rather, you will begin a series of events (as is usual for Qt applications) that you end when both of your threads complete (QThread emits completed () and completed () signals).

+10
source

, Qt QApplication , , . QThread :: finish() , , .

/ Qt join(), , QThread :: wait() - .

bool QThread::wait(unsigned long time = ULONG_MAX)

, :

  • , QThread, (.. QThread::run()). true, . true, .
  • time . ULONG_MAX ( ), ( QThread::run()). false, .

, , , -. , , , " " . , , .

+3

All Articles