Important: Please read the Qt Code of Conduct -

How to wait for a thread to complete?

  • In my main GUI thread, I start a new thread and need to wait until the thread is terminated normally. When waiting the thread, I do not want the main GUI thread loses the reponses, just like WaitForMultipleObjects in Windows SDK API. Is there a similar function that can implement this?


  • Moderators


    It depends on how you started the thread. What class did you use?

    For QThread, listen for the QThread::finished() signal. The signal is emitted when the thread stops. Documentation at

  • You can use something like that:
    @QEventLoop loop;
    connect(thread, &QThread::finished, &loop, &QEventLoop::quit);

  • Hii.

    and if you want to stop/finished your thread before quitting from event loop you can use
    connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater())); as well

Log in to reply