Results 1 to 3 of 3

Thread: QApplication: implementing an 'are you sure?' msgbox on aboutToQuit

  1. #1
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default QApplication: implementing an 'are you sure?' msgbox on aboutToQuit

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QApplication: implementing an 'are you sure?' msgbox on aboutToQuit

    See QWidget::closeEvent(). Notice the example.
    J-P Nurmi

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

    chezifresh (21st April 2009)

  4. #3
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: QApplication: implementing an 'are you sure?' msgbox on aboutToQuit

    Brilliant. I was overloading QWidget.close() instead of close event.

    Thanks +1

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
  •  
Qt is a trademark of The Qt Company.