Yes, I really need to wait. This happens during shutdown, and I need to keep certain objects alive until the thread is finished.
Thank you for your answer. You're right, there is no race condition.
connect(this, SIGNAL(finished()), &eventLoop, SLOT(quit()));
// Note: One might think that there is a race condition where finished() is emitted after
// the call to isFinished(), but before exec(). However, the finished() signal is emitted from
// the QThread, so if the current call lives in another thread (e. g. the main UI thread), the
// Qt::AutoConnection behaves like a Qt::QueuedConnection, and the slot is handled in the
// receiver's thread, i. e. in eventLoop.exec().
if (!isFinished())
eventLoop.exec();
QEventLoop eventLoop;
connect(this, SIGNAL(finished()), &eventLoop, SLOT(quit()));
// Note: One might think that there is a race condition where finished() is emitted after
// the call to isFinished(), but before exec(). However, the finished() signal is emitted from
// the QThread, so if the current call lives in another thread (e. g. the main UI thread), the
// Qt::AutoConnection behaves like a Qt::QueuedConnection, and the slot is handled in the
// receiver's thread, i. e. in eventLoop.exec().
if (!isFinished())
eventLoop.exec();
To copy to clipboard, switch view to plain text mode
Bookmarks