PDA

View Full Version : catch exit event



GrahamLabdon
17th December 2010, 11:14
Hi
My app has a main window and has the usual file->exit menu option.
But the user can also close the main window by using the close button (the cross in top right hand corner) - how can I catch this event?

TIA

Graham

wysota
17th December 2010, 11:41
Reimplement closeEvent() for the window.

GrahamLabdon
17th December 2010, 11:42
what a noob i am!

SixDegrees
17th December 2010, 12:34
Note: this may not be a good idea. You're subverting the window manager's normal way of doing things, and users may be puzzled by this. Unless there's a good reason for doing things this way, I'd advise against it.

Also, if you decide to proceed, poke around in the window flags and see if the "X" close widget can be removed from the window. Again, this is just to avoid possible confusion; it would also eliminate the need to examine events, since there would never be one in such a case.

wysota
17th December 2010, 12:43
Note: this may not be a good idea. You're subverting the window manager's normal way of doing things
Would you elaborate on that, please? What's wrong with reimplementing closeEvent exactly?

SixDegrees
17th December 2010, 13:22
Would you elaborate on that, please? What's wrong with reimplementing closeEvent exactly?

Nothing, in and of itself. I was raising concerns over the subversion of the window's close mechanism in the first place. If the "X" button is left on the window and simply stops working, users are easily confused by this change in standard behavior. To avoid such confusion, I'd favor removing the button altogether. It still "breaks" the traditional user interface design, but at least it's clear that the option isn't even available.

wysota
17th December 2010, 13:32
Well, the OP didn't say he wanted to prevent the window from closing :)

squidge
17th December 2010, 16:53
I think it's a good idea to catch the event to popup a "Do you wish to lose your unsaved work?" dialog. If they answer yes, you can always programmatically close the application.

minirop
18th December 2010, 14:47
If they answer yes, you can always programmatically close the application.
not even. if you dont call "event->ignore()" the window will close anyway.