Since QCoreApplication::quit()
does not work until the event loop is started, you need to defer the call until it starts. So the request queue is a deferred method on quit()
.
The following lines are functionally identical , or one will work:
QTimer::singleShot(0, qApp, &QCoreApplication::quit); //or QTimer::singleShot(0, qApp, SLOT(quit())); // or - see https://stackoverflow.com/a/21653558/1329652 postToThread([]{ QCoreApplication::quit(); }); // or QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection);
source share