Results 1 to 4 of 4

Thread: app.exec() never returns?

  1. #1
    Join Date
    Jun 2007
    Posts
    10
    Thanks
    3

    Default app.exec() never returns?

    Whenever I run my program, the call to app.exec() from the Main function never returns. My program hangs and I end up killing it. This is true if it's run from a debugger or stand alone.

    I'm using Qt 4.2 on Kubuntu 7.04 Linux.

    I tried checking the return code from app.exec(), but since it never returns I never see it. The code executes successfully up to int check = app.exec(), at which point it hangs, though the code doesn't crash.

    Any thoughts?

    EDIT:: I've also tried commenting out all of the code between the declaration of app and the call to app.exec(). It still hangs!?

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. Q_INIT_RESOURCE(application);
    4. QApplication app(argc, argv);
    5.  
    6. ....
    7.  
    8.  
    9. int check = app.exec();
    10. cout << "Check: " << check << endl;
    11. return check;
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by stealth86; 17th July 2007 at 18:08.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: app.exec() never returns?

    Do you create any widget?I mean, a widget that is displayed.
    Because exec() is actually a loop that exits when you call quit or exit.
    When you press the close("x") button in a window, then exit(0) is called. Therefore the event loop exits.

    So, most likely you did not create a main widget.

    If you did, then check your code in other parts of the application. Maybe an infinite loop ?

    Regards

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

    stealth86 (17th July 2007)

  4. #3
    Join Date
    Jun 2007
    Posts
    10
    Thanks
    3

    Default Re: app.exec() never returns?

    Quote Originally Posted by marcel View Post
    Do you create any widget?I mean, a widget that is displayed.
    Because exec() is actually a loop that exits when you call quit or exit.
    When you press the close("x") button in a window, then exit(0) is called. Therefore the event loop exits.

    So, most likely you did not create a main widget.

    If you did, then check your code in other parts of the application. Maybe an infinite loop ?

    Regards
    I think that's it, I'm not yet creating any windows for display. Is there any way to get around this until I'm ready to put up a window? ( Or maybe I'll just dummy it up with a blank widget. )

    Oh, and thanks for the explanation of the exec function.
    I'm pretty new to Qt as you can probably guess, so that was good. :P

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: app.exec() never returns?

    Yes, there is a way.
    All widgets must be created after the QApplication instance.
    Qt Code:
    1. #include <QPushButton>
    2.  
    3. ...
    4. This is where you create the application
    5. ...
    6. QPushButton btn("Temporary button", NULL);
    7. btn.show();
    8. ...
    9. This is the part where you call exec.
    To copy to clipboard, switch view to plain text mode 
    This should do it.
    Regards

Similar Threads

  1. Replies: 4
    Last Post: 8th July 2007, 14:26
  2. no record returns from stored procedure
    By mandal in forum Qt Programming
    Replies: 0
    Last Post: 26th April 2007, 14:45
  3. Replies: 1
    Last Post: 13th March 2007, 17:33
  4. Replies: 4
    Last Post: 27th July 2006, 11:13
  5. connect returns false
    By krivenok in forum Qt Programming
    Replies: 6
    Last Post: 21st February 2006, 20:01

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.