Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect Windows shutdown or logoff in Qt

I am porting a Linux app to Windows written in Qt. The application needs to save some settings before closing. On Linux, we can do that by signal handlers for SIGTERM etc. How can I implement the same on Windows.

like image 537
adnan kamili Avatar asked Oct 05 '13 09:10

adnan kamili


1 Answers

If you are using the Qt event loop, you can catch the following signal:

void QCoreApplication::aboutToQuit() [signal]

This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session. The signal is particularly useful if your application has to do some last-second cleanup. Note that no user interaction is possible in this state.

Other than that, you may be looking for the following messages below if the aforementioned signal is not appropriate for your use case:

WM_QUIT: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632641(v=vs.85).aspx

WM_CLOSE: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632617(v=vs.85).aspx

WM_QUERYENDSESSION: http://msdn.microsoft.com/en-US/library/windows/desktop/aa376890.aspx

WM_ENDSESSION: http://msdn.microsoft.com/en-US/library/windows/desktop/aa376889.aspx

like image 73
lpapp Avatar answered Sep 20 '22 23:09

lpapp