Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to wait for a thread to complete?
chcw last edited by
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?
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 https://qt-project.org/doc/qt-5/qthread.html
qxoz last edited by
You can use something like that:
connect(thread, &QThread::finished, &loop, &QEventLoop::quit);
IamSumit last edited by
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