Results 1 to 9 of 9

Thread: catch exit event

  1. #1
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default catch exit event

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: catch exit event

    Reimplement closeEvent() for the window.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    GrahamLabdon (17th December 2010)

  4. #3
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: catch exit event

    what a noob i am!

  5. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: catch exit event

    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.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: catch exit event

    Quote Originally Posted by SixDegrees View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: catch exit event

    Quote Originally Posted by wysota View Post
    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.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: catch exit event

    Well, the OP didn't say he wanted to prevent the window from closing
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: catch exit event

    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.

  10. #9
    Join Date
    Jan 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: catch exit event

    Quote Originally Posted by squidge View Post
    If they answer yes, you can always programmatically close the application.
    not even. if you dont call "event->ignore()" the window will close anyway.

Similar Threads

  1. How to catch event, then objectName changed.
    By sergey_85 in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2010, 20:05
  2. how to catch close event in this program? [pyqt]
    By pyqt123 in forum Qt Programming
    Replies: 15
    Last Post: 14th December 2009, 11:30
  3. Catch click Hyperlink event
    By summer_of_69 in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2009, 19:43
  4. Catch a row selection event in QTableView
    By Windsoarer in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2009, 22:44
  5. Replies: 2
    Last Post: 24th November 2008, 15:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.