PDA

View Full Version : QApplication: implementing an 'are you sure?' msgbox on aboutToQuit



chezifresh
21st April 2009, 23:38
I have an application that on exit I want it to ask the user if they want to save their work. This is trivial when they click on the File->Exit menu item because I control when and what gets called. However, if the user clicks on the 'X' in the window frame then this becomes a more difficult problem.

I can hook up to the aboutToQuit signal but that gets called after the GUI is hidden and about to be killed. But I want a standard message box that says 'Save', 'Discard', 'Cancel', where cancel would abort closing the application. (Like firefox when it asks you if you want to save your tabs, quit or cancel).

That doesnt make sense if the main window is already hidden, then you're just left with a floating message box. If you did nothing else than click cancel the main window would already have been hidden and the application would exit.

Any ideas? This has to be a solved problem, I just can't seem to find anything good in the documentation

jpn
21st April 2009, 23:43
See QWidget::closeEvent(). Notice the example.

chezifresh
21st April 2009, 23:46
Brilliant. I was overloading QWidget.close() instead of close event.

Thanks +1