2007-03-31

Windows, CMake and console

When playing around with Qt on Windows one always runs into the console issue. Some sooner, others later. The problem is that a Windows application does not have a console by default. When thinking about this, it is pretty obvious, given the nature of Windows.

This means that qDebug and friends cannot output to anything, so you don't get any feedback at run-time. The solution to this has always been to add a line reading CONFIG += console in the project file.

Now I'm trying to find out how this is handles when I'm building using CMake. Does anybody know? Please leave a comment!

9 Comments:

At 9:28 PM, Blogger Brcha said...

Are you using gcc? I have (had) a different problem. When I compile a Qt program for Windows (using CMake), I get a program that opens a console and a GUI (which is not what I wanted). To get rid of that I did one fork() at the beginning of the program so that the "real" program runs in the background. That way I got rid of the console.

A few days ago I found out that I can put a -mwindows option to gcc while linking and then the resulting program will not have the console.

If you do want to have a console, then add the -mconsole option while linking as well as the -mwindows.

I am not using Windows at all, but I have to compile programs for Windows, so I installed MinGW & Qt4 & CMake under Wine (under GNU/Linux). It works very nice, btw. What I want to say is that I haven't thorowly tested the above solution. I tried it once and it worked. So I guess you could give it a try. Just add "-mwindows -mconsole" to LINK_FLAGS variable.

That should be something like:

set(LINK_FLAGS "${LINK_FLAGS} -mwindows -mconsole")

Best regards
Brcha

 
At 9:31 PM, Anonymous wysota said...

I don't think this is so obvious. It could be that it opens a console window when it is first referred to or that it writes the output to some kind of global log. Output shouldn't vanish into thin air. It's just a design decision and we can argue if it's a good or a bad one.

 
At 4:59 AM, Blogger Simon said...

I have this set for TARGET_LINK_LIBRARIES:
"-Wl,-subsystem,console"

And then you get a console :)

 
At 10:38 AM, Anonymous Philippe Fremy said...

Another way to handle that is to go without console, but use DebugView (previously on sys-internals, now on Microsoft technet)

All output sent to qDebug, qWarning and qError is sent on windows to a special debugging interface, whose output you can capture with DebugView.

 
At 10:48 AM, Blogger Johan Thelin said...

This sounds hopeful - will try it this afternoon. I found a download link here: http://www.microsoft.com/technet/sysinternals/Miscellaneous/DebugView.mspx .

 
At 10:28 AM, Anonymous Wysota said...

You can do the same with Qt-only - by using qInstallMsgHandler(). Unfortunately you have to put some code into the application itself...

 
At 11:41 AM, Anonymous Anonymous said...

You can enable console in QT applications by adding an element 'console' to CONFIG line in file C:\Qt\4.2.2\mkspecs\win32-g++\qmake.conf (on my computer). Later, if you build for end users, you just remove it. Tamas Ungi

 
At 12:29 PM, Anonymous mahmood said...

CONFIG += console does not work for me. what is wrong?

 
At 1:06 PM, Blogger Johan Thelin said...

You need to rebuild your app. Try running make distclean and then qmake and make again.

 

Post a Comment

<< Home