@Bonnie said in QThread does not quit, why?:
The solution is
QObject::connect(myControl, &Control::finished, myThread, &QThread::quit, Qt::DirectConnection);
And where does it say that this slot is thread-safe?
@robro
Just quit the thread before you exit the application.
QObject::connect(&app, &QApplication::aboutToQuit, myCtrl, &Control::deleteLater);
QObject::connect(myCtrl, &Control::finished, &myThread, &QThread::quit);
QObject::connect(&myThread, &QThread::finished, myCtrl, &Control::deleteLater); //< This is needed
Which translates simply to:
qDebug() << "Started Waiting:";
myThread.quit();
myThread.wait(); // Wait for thread to quit
qDebug() << "Quit";