Results 1 to 4 of 4

Thread: Terminating a console app

  1. #1
    Join Date
    Aug 2010
    Location
    Joplin, Mo
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Terminating a console app

    I have a small console app that will do some post install file & text proccessing. I need it to be self terminating & I need it to NOT show a console while running. I tried a.quit() & a.exit() to terminate, but neither one worked. I'm not sure how to supress the console window. The app will run on Win.

    Any help is appreciated.

    Thanx,

    Ed

    Qt Code:
    1. #include <QTextStream>
    2. #include <QString>
    3. #include <QFile>
    4.  
    5. QTextStream cout(stdout, QIODevice::WriteOnly);
    6. QTextStream cerr(stderr, QIODevice::WriteOnly);
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QCoreApplication a(argc, argv);
    11. QString str1, str2;
    12. QFile file("fixPath.txt");
    13. if(file.open(QIODevice::ReadOnly))
    14. {
    15. QTextStream in(&file);
    16. while (not in.atEnd())
    17. {
    18. str1 = in.readLine();
    19. cout << str1 << endl;
    20. }
    21. file.close();
    22. }
    23.  
    24. return a.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Terminating a console app

    Suppressing the console window: Does
    Qt Code:
    1. CONFIG -= console
    To copy to clipboard, switch view to plain text mode 
    in your Pro file do it for you? Of course, you have to have somewhere for your cout and cerr streams to go.

    If you don't enter the event loop, i.e. don't call QCoreApplication::exec(), then the program just runs straight through to completion.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Terminating a console app

    Quote Originally Posted by cejohnsonsr View Post
    I tried a.quit() & a.exit()
    This is a common problem. You need to let the program enter the event loop.
    To quit, you can use a timer with a singleshot for about 100ms and call the slot quit().

  4. #4
    Join Date
    Aug 2010
    Location
    Joplin, Mo
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Terminating a console app

    Thank you for the answers. I'm learning & relearning a little at a time.

    Ed

Similar Threads

  1. QT Console app
    By yorkshireflatcap in forum Newbie
    Replies: 14
    Last Post: 22nd June 2010, 20:57
  2. Problem with Qt console
    By Nishant in forum Installation and Deployment
    Replies: 3
    Last Post: 15th October 2009, 12:05
  3. Terminating QThread error
    By ramazangirgin in forum Qt Programming
    Replies: 9
    Last Post: 24th August 2008, 18:18
  4. Replies: 19
    Last Post: 21st January 2008, 09:13
  5. Terminating a thread.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 9th July 2007, 11:14

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.