views:

388

answers:

5

For whatever reason, std::cout does not display anything with my application. The description of my development environment follows.

I am working on a Qt application using Qt Creator. Since Qt Creator can't be launched from my station (XP64), i am currently developping it with Visual Studio 2008 and the Qt plugin (by importing the .pro project file). Everything seems fine and the application works.

In some cases (depending on command line arguments), i don't want to launch the HIM, just to display a few sentences in the CLI (command line required arguments, for instance).

I don't get any error, but nothing is displayed. The corresponding code, which i am sure is run is the (classical) following :

std::cout << "is this going to be displayed ?" << std::endl;

Do you have any idea why nothing is displayed ?

+4  A: 

Windows distinguishes between console applications and GUI applications, and does not create a console for GUI applications, by default (see this page from MSDN). You can use AllocConsole to create one.

Michael Aaron Safyan
I have tried launching it from "cmd"
Benoît
@Benoit, it doesn't matter where you launch it... it depends entirely on the application, itself (whether is uses the WinMain or other functions associated with the Windows GUI).
Michael Aaron Safyan
Yes, i get that now.
Benoît
It's not only the console that needs to be created, it is also the standard file handles for in, out and err that need to be opened
sbk
+1  A: 

Ok, answer found. Simple answer, of course, as always when encountering such problems. Michael Aaron was on the right tracks.

Simply changing SubSystem to Console in project configuration (/Configuration properties/Linker/System) makes the whole thing work. The GUI still works, but with a background console. I can deal with that.

Benoît
A: 

Perhaps it's not the std::cout line that makes it not displayed, but the function containing it. Maybe it's not invoked at all, and that's why std::cout doesn't work.

manuel
+4  A: 

One trick for SUBSYSTEM:WINDOWS applications is that even though there's no console, you can still pipe stdout and stderr. So you can do:

YourApplication.exe > output.txt

or if you have cat (or an equivalent):

YourApplication.exe | cat
jamesdlin
I did not know that. Thanks.
spong
A: 

Try

CONFIG += console

in your .pro file.

ktk