Results 1 to 3 of 3

Thread: application never quits

  1. #1
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default application never quits

    hello! I'm writing the following application:

    main.cpp:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include <QInputDialog>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. MainWindow w;
    10.  
    11. bool ans1, ans2;
    12. int i1 = id.getInt(&w, w.tr("Title"), w.tr("Text"),0,0,20,1,&ans1));
    13. int i2 = id.getInt(&w, w.tr("Title"), w.tr("Text"),0,0,20,1,&ans2));
    14.  
    15. if (ans1 && ans2)
    16. {
    17. w.showMaximized();
    18. }
    19. else
    20. {
    21. w.close();
    22. }
    23.  
    24. return a.exec();
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 

    If I chose "OK" for both the first input dialog and the second one then the program continues rightly and clicking the classic "X" it exits correctly.
    While if I chose "Cancel" in one of the input dialogs the window doesn't show (and I want it) but the application doesn't quit at all. It remains running in RAM.
    I found this behaviour by debugging the program putting a breakpoint at the row "return a.exec();". This instruction never stop (so the program loops in the exec() function). what can it be?

    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: application never quits

    it runs because it is not stopped by e.g. closing the last window. but you can simply avoid it by writing
    Qt Code:
    1. return 0;
    To copy to clipboard, switch view to plain text mode 
    in your else brace.

  3. #3
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: application never quits

    thanks, it worked

Similar Threads

  1. Application won't quit until event loop quits
    By caelestis in forum Qt Programming
    Replies: 6
    Last Post: 11th February 2010, 07:21
  2. Replies: 3
    Last Post: 6th January 2010, 16:55
  3. Qt 4 quits application [solved]
    By osiris81 in forum Qt Programming
    Replies: 1
    Last Post: 3rd December 2008, 14:07
  4. Replies: 12
    Last Post: 29th February 2008, 13:35
  5. hide() quits?
    By Morea in forum Newbie
    Replies: 13
    Last Post: 25th February 2006, 19:40

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.