Results 1 to 3 of 3

Thread: Application not exiting gracefully if I want close to in CMainWindow ctor

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Application not exiting gracefully if I want close to in CMainWindow ctor

    In QMainWindow, I'm initializing a CWorker class and this CWorker tries to find if a particular shared memory is available. If shared memory isn't available then I should quit the application (i.e., QMainWindow).
    I'm trying to check this in try.. catch. So if the control goes to catch, I'm trying to display a QMessageBox & exit(this->close) the application. While doing this, the application is not closing gracefully.

    Qt Code:
    1. CMainWindow::CMainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. ....
    5. ....
    6. try
    7. {
    8. worker = new CWorker();
    9. }
    10. catch(...)
    11. {
    12. QMessageBox::information(this, "Title",
    13. "Message text goes here");
    14. quit();
    15. }
    16.  
    17. ....
    18. ....
    19. ....
    20. }
    To copy to clipboard, switch view to plain text mode 

    I tried qApp->quit() and QCoreApplication::quit(); also but same result;

    Please find the attached screenshot of the error message after the application goes to catch().

    QuitApp.jpg
    Last edited by rawfool; 27th July 2013 at 12:29.

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

    Default Re: Application not exiting gracefully if I want close to in CMainWindow ctor

    At the time when constructors are called, the event loop is not running yet, thus trying to quit it is a no-op.
    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:

    rawfool (30th July 2013)

  4. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Application not exiting gracefully if I want close to in CMainWindow ctor

    Add a dummy statement behind the new and set breaks at new and in the catch block. Debug. This way, you will localize the problem. If it is the quit() (GP fault or the app tries to continue normally) then you'd better rethrow from the CMainWindow ctor and put try - catch in your main(). You should end in the catch block here. You can exit() simply because all objects created in the try block of the main() are already destructed.

  5. The following user says thank you to Radek for this useful post:

    rawfool (30th July 2013)

Similar Threads

  1. Replies: 1
    Last Post: 13th September 2011, 09:56
  2. QT application not close after close the mainwindow
    By artome in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2011, 22:23
  3. Replies: 2
    Last Post: 7th July 2011, 10:20
  4. Replies: 2
    Last Post: 17th December 2010, 19:01
  5. Exiting a Qt Console Application
    By nbetcher in forum Qt Programming
    Replies: 4
    Last Post: 23rd March 2009, 21:03

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.