Results 1 to 7 of 7

Thread: Console application suspense

  1. #1
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Smile Console application suspense

    I believe I am correct in stating that Qt applications are console applications. My question is this: in Windows, if you run a qt executable from command line, the program starts but immediately gives control back to the console. This prevents the user from seeing couts, cerrs, printfs etc... I know you can output all of this to a file using sample.exe>output.txt for instance, but is there any way to keep control of the command window?

  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: Console application suspense

    No. Qt applications are real GUI applications. Nobody says GUI apps can't take command line arguments or that they can't be run from the command line.
    If you want to write a console application, use QCoreApplication instead.

    You can print stuff to stdout before calling QCoreApplication::exec(). exec is the one that starts the event loop and gives control to your application.

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

    TheGrimace (24th September 2007)

  4. #3
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Console application suspense

    Ok, so if I used QCoreApplication instead of QApplication for the main, then I would retain control? Or I would maintain control until calling exec?

  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: Console application suspense

    You will have to output everything before calling exec.
    You could also catch key events and exit when the user presses a key, or something similar.

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

    TheGrimace (1st October 2007)

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

    Default Re: Console application suspense

    Add "CONFIG+=console" to your project file, run qmake and recompile your project. Then everything will become clear.

  8. The following user says thank you to wysota for this useful post:

    TheGrimace (1st October 2007)

  9. #6
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Console application suspense

    Too much effort for not enough payoff. I was hoping it might be a bit simpler

    Thank You for the quick response, marcel.

  10. #7
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Console application suspense

    Just checked this post again and noticed I missed wysota's response. Thank You as well. I will try that.

Similar Threads

  1. Replies: 8
    Last Post: 28th January 2015, 09:45
  2. dll + application
    By fpujol in forum Qt Programming
    Replies: 11
    Last Post: 15th April 2007, 18:37
  3. build a gui ontop of a console application
    By aegis in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2007, 12:16
  4. Help sought on console + GUI Integration...
    By mysearch05 in forum Newbie
    Replies: 7
    Last Post: 28th January 2006, 14:41

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.