I have created a QThread and worker, moved the worker to the thread, and starts fine. When I want to shutdown my app gracefully I want to tell the thread to quit; which SHOULD cause the worker’s destructor to be called. But it’s not! I have a qDebug statement in the worker’s dtor and it never runs.
As a test, a creator a “testFinished” slot (in the parent) which DOES run. Why is the worker’s dtor never executed? And how do I fix this.
connect(myThread, SIGNAL(started()), worker, SLOT(slot_start()),Qt::QueuedConnection);
connect(myThread, SIGNAL(finished()), worker, SLOT(deleteLater()),Qt::QueuedConnection);
connect(myThread, SIGNAL(finished()), myThread, SLOT(deleteLater()), Qt::QueuedConnection);
connect(myThread, &QThread::finished, this, &MonitorAgent::testFinished, Qt::QueuedConnection);
// Do some stuff here...then stop the thread
myThread->quit(); // Exit the event loop
myThread->wait(10000); // Wait up to 3 seconds
I tried inserting some QCoreApplication::processevents() but that made no difference (per other posts).