Use the aboutToQuit() signal instead.
This signal is emitted when the application is about to exit the main event loop, for example. when the event loop level drops to zero. This can happen either after calling the quit () function from the application, or when users close the entire desktop session.
A signal is especially useful if your application needs a last-second cleanup. Please note that state interaction is not possible in this.
For instance:
connect(this, SIGNAL(aboutToQuit()), this, SLOT(updateDatabase()));
source share