Results 1 to 15 of 15

Thread: How to exit Qt console application?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to exit Qt console application?

    What is the advantage of your code over this one?

    Qt Code:
    1. int main(int argc, char **argv) {
    2. QCoreApplication a(argc, argv);
    3. Sasaja sasaja;
    4. return sasaja.DoWork();
    5. }
    To copy to clipboard, switch view to plain text mode 
    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.


  2. #2
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to exit Qt console application?

    The difference is there is no event loop running.
    Whether that is an advantage or not depends on what DoWork does.

    Karl

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

    Default Re: How to exit Qt console application?

    In your version the event loop is not running as well since you exit it immediately after handling the slot which is started immediately after you call exec(). The only difference would be if the constructor of Sasaja scheduled any events by itself that would execute before the DoWork slot did.
    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.


  4. #4
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to exit Qt console application?

    We use this method to write server daemons.
    We create a private slot that watches for signals that tell the application to exit.
    Without the signal, the program continues to run.

    Karl

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

    Default Re: How to exit Qt console application?

    Quote Originally Posted by KaptainKarl View Post
    We use this method to write server daemons.
    We create a private slot that watches for signals that tell the application to exit.
    Without the signal, the program continues to run.
    So what is the purpose of the single-shot timer? How does the program "continue to run" if while you exit the slot, you call application's exit() slot which quits the event loop? Could you provide a minimal compilable example demonstrating what you mean?
    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.


Similar Threads

  1. Console application beginning
    By Raccoon29 in forum Newbie
    Replies: 6
    Last Post: 23rd March 2012, 23:42
  2. about console application
    By jirach_gag in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2012, 11:39
  3. open console application
    By hirakjyoti in forum Newbie
    Replies: 1
    Last Post: 30th January 2011, 16:34
  4. Replies: 2
    Last Post: 21st November 2010, 18:03
  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
  •  
Qt is a trademark of The Qt Company.