Results 1 to 5 of 5

Thread: Exiting a Qt Console Application

  1. #1
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Exiting a Qt Console Application

    Hello,
    I am developing a Qt console application and have run into a snag: the application does not quit when told to using 'exit(1);' The class is constructed with QCoreApplication as the parent and within the constructor I parse the command-line parameters passed to the application. If there are no parameters passed or '-h' or '--help' is passed then the application prints the usage help, then quits. Unfortunately the program does not quit after printing the help, then being instructed to exit().

    When it prints the help it calls a function to automate that task, and in that function a QTextStream is created against stdout. The help is printed using lines such as this (where 'console' is the QTextStream(stdout) ):

    Qt Code:
    1. console << "Exit status is 0 if OK, otherwise failure." << endl;
    To copy to clipboard, switch view to plain text mode 

    Once the help is printed the function simply ends. It then returns back into the constructor's loop to finish construction and exit(1) is called, but the application doesn't exit. I've also tried 'qApp->exit(1)' to make sure that no funny-business was going on.

    Also, the main.cpp file DOES contain 'return a.exec()' where 'a' is the QCoreApplication class constructed.

    What is the reason the program is not exiting? Can exit() not be called in the constructor?

    Thanks,
    Nick Betcher, CPhT

  2. #2
    Join Date
    Mar 2009
    Posts
    25
    Thanked 2 Times in 2 Posts

    Default Re: Exiting a Qt Console Application

    void QCoreApplication::exit ( int returnCode = 0 ) [static]

    Tells the application to exit with a return code.

    After this function has been called, the application leaves the main event loop and returns from the call to exec(). The exec() function returns returnCode. If the event loop is not running, this function does nothing.


    If you meant to call the exit() in the standard C library, type std::exit.

  3. #3
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Exiting a Qt Console Application

    Quote Originally Posted by Hiker Hauk View Post
    void QCoreApplication::exit ( int returnCode = 0 ) [static]

    Tells the application to exit with a return code.

    After this function has been called, the application leaves the main event loop and returns from the call to exec(). The exec() function returns returnCode. If the event loop is not running, this function does nothing.


    If you meant to call the exit() in the standard C library, type std::exit.
    Huh? No, for sake of simplicity I just didn't type QCoreApplication::exit() everytime I referred to it. The code has QCoreApplication::exit(1); in the constructor, but the application does not exit. I did not want to call std::exit. Thanks for the help, but the application still does not exit the event loop.

  4. #4
    Join Date
    Mar 2009
    Posts
    25
    Thanked 2 Times in 2 Posts

    Default Re: Exiting a Qt Console Application

    Quote Originally Posted by Hiker Hauk View Post
    void QCoreApplication::exit ( int returnCode = 0 ) [static]

    Tells the application to exit with a return code.

    After this function has been called, the application leaves the main event loop and returns from the call to exec(). The exec() function returns returnCode. If the event loop is not running, this function does nothing.


    If you meant to call the exit() in the standard C library, type std::exit.
    Maybe read again.

  5. #5
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Exiting a Qt Console Application

    Quote Originally Posted by Hiker Hauk View Post
    Maybe read again.
    Ok. You know what's funny, I actually started to reply to the fact that I still didn't understand my problem, but in typing up the reply I realized what it was. So, as I suspected, I can't call that in the constructor. That's what I get for replying this morning to your message... I wasn't awake.

    Thanks.

Similar Threads

  1. Replies: 8
    Last Post: 28th January 2015, 10:45
  2. about console application
    By jirach_gag in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2012, 12:39
  3. libGL using memory in console application
    By neuron in forum Qt Programming
    Replies: 0
    Last Post: 11th March 2009, 16:52
  4. Console application suspense
    By TheGrimace in forum Newbie
    Replies: 6
    Last Post: 1st October 2007, 15:52
  5. build a gui ontop of a console application
    By aegis in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2007, 13:16

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.