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?