[Qt-interest] What makes an application show a console?
Steven Doerfler
sgd-qt at lugaru.com
Mon May 10 16:51:29 CEST 2010
On 5/9/2010 2:14 PM, Gabriele Kahlout wrote:
>
> My GUI application also starts a cmd.exe window, along the window.
> While other qt gui projects i create in qt creator (to compare) don't.
> What could be in the DNA of my app to require that console?
In Windows, console programs are marked by a flag in the executable's
header. One way to check for the flag is to use Cygwin's file(1)
command. It prints "GUI" or "console" based on this flag.
You can also test for the console flag by running your program from a
cmd.exe prompt. If cmd.exe waits for your program to exit before
displaying another prompt, then it's a console program. If cmd.exe
immediately shows another prompt, then your program is marked as a GUI
program.
(It's also possible for a program without the console flag to create one
or more console windows, but I think programs have to do this
explicitly. I've never heard of Windows automatically creating a
console window for a GUI program that fails to create a window fast
enough. I don't think a GUI program could use such a console window
anyway, since it wouldn't have inherited a handle to it, as a console
program would.)
The linker adds the console flag to an executable based on a command
line parameter like "/subsystem:console" (Microsoft's linker) or
"-Wl,-subsystem,console" (Gnu linker). With qmake, that setting in turn
derives from CONFIG containing console. You can check for those flags
in your Makefile.Debug file.
Are you using testlib in your program? The file
qt/mkspecs/features/qt.prf has some code that forces CONFIG += console
for any program that uses testlib. If not testlib, perhaps your .pro
file uses some other library with similar magic. The makefile for a Qt
program includes lots of .prf files, any one of one which can set CONFIG.
Steven
More information about the Qt-interest-old
mailing list