PDA

View Full Version : Pro's and con's of using close event instead of destructor



Teuniz
26th November 2009, 19:59
My program needs to save some settings to a file when a user closes or exits the program.

Question, what is the best approach, calling the function that saves the settings from the destructor of QMainWindow or call it from closeEvent(QCloseEvent *event) ?

Another question, which function will be called first when a user quit the program, the destructor or the close event?

john_god
26th November 2009, 23:57
The close event will be called first.
I believe this is the best place because you can ask the user to save or not the data and you can allow wthe user not to close the program, with the event->ignore();
Check the main application example (http://qt.nokia.com/doc/4.5/mainwindows-application.html)