[Interest] Handling WM_QUIT messages when no window is shown
Julius Bullinger
julius.bullinger at gmail.com
Wed May 6 11:09:27 CEST 2020
Usually, sending a WM_QUIT message to a QApplication triggers the
QCoreApplication::aboutToQuit() signal, e.g. when ending the application
via Windows's Task Manager, or using "taskkill /PID <pid>".
We discovered that no aboutToQuit() signal is emitted when a
QApplication without windows receives a WM_QUIT:
#include <QApplication>
#include <QDebug>
#include <QWidget>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QApplication::connect(&app, &QApplication::aboutToQuit, []() {
qDebug() << "QApplication::aboutToQuit";
});
// Commenting those lines will not trigger aboutToQuit() when
// the application is closed via Task Manager:
QWidget w;
w.show();
return app.exec();
}
Our application supports a text-only variant, where the GUI is disabled.
We're basically doing it like that, and wondered why our shutdown code
was not called when the application was quit via the Task Manager.
Is there anything that needs to be done to get consistent behavior?
More information about the Interest
mailing list