Results 1 to 2 of 2

Thread: clean exit!!

  1. #1
    Join Date
    May 2008
    Posts
    12
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default clean exit!!

    I have a console based app code is like this,

    Qt Code:
    1. #include <QApplication>
    2. #include <iostream>
    3. using namespace std;
    4.  
    5. class dummy : public QObject
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. void callme()
    11. {
    12. cout <<"callme()";
    13. emit taskCompleted();
    14. }
    15. signals:
    16. void taskCompleted();
    17. };
    18. #include "main.moc"
    19. int main(int argc, char *argv[])
    20. {
    21. QApplication myapp(argc,argv);
    22.  
    23. dummy me;
    24.  
    25. QObject::connect (&me,SIGNAL(taskCompleted()),&myapp,SLOT(quit()));
    26. me.callme();
    27. return myapp.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 
    It never makes clean exit, it just hangs. once taskCompleted is emitted it should call quit and make clean exit. Is it expected or am I wrong here ?? I have to press ctrl+c to exit.

    thanks,
    Raajesh
    Last edited by marcel; 17th June 2008 at 14:21. Reason: missing [code] tags

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: clean exit!!

    Your signal is emitted before the event loop is started.
    I.e. you start the event loop after the signal was emitted...

    If the code works that way, you can just replace
    Qt Code:
    1. return myapp.exec();
    To copy to clipboard, switch view to plain text mode 
    by
    Qt Code:
    1. return 0;
    To copy to clipboard, switch view to plain text mode 

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

    abrou (25th August 2008)

Similar Threads

  1. Downloading from a clean url
    By travlr in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2007, 21:55
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. ways to exit appl.
    By whoops.slo in forum Newbie
    Replies: 1
    Last Post: 29th January 2007, 18:18
  4. Clean project deletes makefile
    By Djony in forum Qt Programming
    Replies: 2
    Last Post: 7th December 2006, 10:15
  5. How to capture exit slot of main window
    By jyoti kumar in forum Newbie
    Replies: 2
    Last Post: 31st May 2006, 07:06

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.