I have caught the closeEvent from QMainWindow in my application, in order to show a "Are you sure?" popup to the user, if he closes the app with the "X" button.
Unfortunately the popup creates problems if the application is closed from Windows itself during the shutdown.
I would like to differentiate the behaviour if the app was closed using the "X" button or by the OS itself.
Is it possible?
I tried to use the aboutToQuit signal from Qt, but the popup appears before the signal is received from my app. So this signal does not help me...
In windows two messages are send to all windows when shutdown initiated:
WM_QUERYENDSESSIONandWM_ENDSESSION, they are transformed intoQtWindows::QueryEndSessionApplicationEventandQtWindows::EndSessionApplicationEvent. This events are handled inQWindowsContext::windowsProc: first one callsQApplication::commitDataon application instance, which emitscommitDataRequest()from session manager instance, and second one emitsaboutToQuit()from application instance.Relevant part of Qt called Session Management and includes a set of platform specific QSessionManager classes. Here's what documentation recommends:
Here's example from documentation how you can do this: