I\'d like to do some house keeping stuff (like writing to a file etc) in a Qt app before the app exits. How can I get to this function (exit or whatever is called) in Qt?
In regards to Silas Parker's answer, the Qt documentation says this about the aboutToQuit
signal:
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.
If you want your application to be able to cancel the exiting process or allow the user to perform a last minute change before the application closes, then you can do this by handling the closeEvent
function in your MainWindow
.
void MainWindow::closeEvent(QCloseEvent *event)
{
if (maybeSave()) {
writeSettings();
event->accept();
} else {
event->ignore();
}
}
See the closeEvent documentation for more information.