PDA

View Full Version : Redirecting stdout to a console in Qt



geotdw
22nd March 2012, 19:42
Hi,

I've read mulitple threads related to what I'm looking for, but none answered the questions that I have.

Basically what I want to do is the following,

I have a Qt application that is a GUI. This application will sometimes instead of being executed with a double click (.exe), will be run from the command line with some variables.
Now, if it's run from command line and (argc > 1), then I would like to print messages to this console (Note: not in another window).

Now I noticed that if I don't put CONFIG += console in my .pro, then all my qDebug or printf messages do not get printed. I do not want to run my application as a console application
because when I double click I will get an unwated console window which is not what I want.

I also do not like the way another thread had found the solution where I have to projects, one .com and one .exe and in main according to the no. of arguments decide which one to run.
Another solution that I did not like is attaching a console to the app if arguments is present, because then when I run the app from command line, I get another window that pops up.

Basically what I want to know is, if there is a call that I could do to find out if the app was run form a commandline, and if so then get the console's like processor's id or something and then
redirect all my print messages to that console window (where the application was run from).

thanks

amleto
24th March 2012, 10:43
"Basically what I want to know is, if there is a call that I could do to find out if the app was run form a commandline"

No, I don't think so.