Results 1 to 6 of 6

Thread: How works QApplication::exit()

  1. #1
    Join Date
    Nov 2010
    Location
    Cienfuegos, Cuba
    Posts
    16
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How works QApplication::exit()

    On my application I try to retrieve data from a database. If this step is succesfull the application continues, Instead I want that the application shows a QMessage::critical(...) and closes with QApplication::exit(). The error appears but the application dosn't stops. The code is:

    Qt Code:
    1. wMain::wMain(QWidget *parent) : QWidget(parent), ui(new Ui::wMain)
    2. {
    3. ui->setupUi(this);
    4. this->actualizarInterfaz();
    5. }
    6.  
    7. void wMain::actualizarInterfaz()
    8. {
    9. DAO* aDao = new DAO("");
    10. this->asg = aDao->Query(1);
    11. delete aDao;
    12.  
    13. if(this->asg != NULL)
    14. {
    15. // populate gui with data recovered
    16. }
    17. else
    18. {
    19. QMessageBox::critical(
    20. this,
    21. "Error",
    22. "...");
    23. qApp->exit(1);
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    How could I fix this? There are another ways to do it?

  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: How works QApplication::exit()

    What exactly do you mean that the application "doesn't stop"? Did you read about differences between QCoreApplication::exit() and ::exit()?
    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. #3
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: How works QApplication::exit()

    I agree with wysota. In this case, I'm just figure how qApp->exit() called. I guess that your problem is calling QApplication::exit() before entering the application main loop. In the other word, QApplication::exit() called before QApplication::exec() executed. So if you want to stop your application before QApplication entering the main loop, call ::exit() that provided by stdlib.h.

  4. #4
    Join Date
    Apr 2011
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How works QApplication::exit()

    I discovered another way to quit your Qt app before the main event loop has started a couple of days ago. I needed to quit the application within the constructor of the main window, and it seems that the following does the job:

    Qt Code:
    1. QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 

    X-T

  5. #5
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: How works QApplication::exit()

    I discovered another way to quit your Qt app before the main event loop has started.
    That's not TRUE, in fact the application event loop has started and the Widget costructed, show, then closed by method invocation. You are misunderstand with Qt:QueuedConnection. Do you actually know what you've done?
    ~ We are nothing in this universe ~

  6. #6
    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: How works QApplication::exit()

    If you want to quit the application then just return from main.
    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. The following user says thank you to wysota for this useful post:

    anoraxis (12th March 2012)

Similar Threads

  1. cannot exit from fullscreen
    By lazycoder in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2011, 06:38
  2. Exit Code 3
    By RSX in forum Newbie
    Replies: 4
    Last Post: 11th March 2011, 00:44
  3. QtConcurrent::run() and exit()
    By pmitas in forum Newbie
    Replies: 8
    Last Post: 24th September 2010, 10:12
  4. clean exit!!
    By Raajesh in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2008, 16:33
  5. <QtGui/QApplication> vs. <QApplication>
    By seneca in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2006, 10:58

Tags for this Thread

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.