PDA

View Full Version : Console application suspense



TheGrimace
24th September 2007, 17:30
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?

marcel
24th September 2007, 17:51
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.

TheGrimace
24th September 2007, 17:57
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?

marcel
24th September 2007, 18:07
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.

wysota
24th September 2007, 18:17
Add "CONFIG+=console" to your project file, run qmake and recompile your project. Then everything will become clear.

TheGrimace
24th September 2007, 18:20
Too much effort for not enough payoff. I was hoping it might be a bit simpler

Thank You for the quick response, marcel.

TheGrimace
1st October 2007, 14:52
Just checked this post again and noticed I missed wysota's response. Thank You as well. I will try that.