views:

727

answers:

5

i have a Qt application.

when i run this application, there is a console opening behind the application. in development it is nice because i see debug outputs on the console.

now, i want to give this executable to the customer and i dont want to any console window. how can i hide it??

(ps. i use Visual Studio 2008)

A: 

Hey,

I would suggest to check the presence of the following line in your .PRO file :

CONFIG += console

If you can find it, remove it ! It should fix your issue !

Hope it helps !

Andy M
but visual studio does not use .PRO file. it just exports/imports this file..
ufukgun
The actual Visual Studio project is created using the configuration parameters in the QMake project file, so this could very well be the cause.
Veeti
Erm, in the VCProj properties, maybe by going in Links Edition, System and finally Subsystem... Try putting the value "Windows (/SUBSYSTEM:WINDOWS)"... I'm not really sure you can do it like that tho...
Andy M
I quickly tested in one of my application and for some obscure reason, i need to add the following lib :c:\...\Qt\4.6.0-vs2008\lib\qtmain.libin VCProj Properties-> Links Edition -> Entry -> Additionnal Dependencies
Andy M
And it looks like it's the final solution :)http://lists.trolltech.com/qt-interest/2005-12/thread00170-0.html
Andy M
+2  A: 

May be the better option will be not to simply remove (as Andy M suggested) but edit *.pro file adding something like

CONFIG(debug, debug|release) {
    CONFIG *= console
} 
else {
    CONFIG -= console
}

In debug you can see console window but not in release. I like it. =)

kemiisto
+5  A: 

It sounds like your linker configuration is incorrect. Right-click the project, Properties, Linker, System, SubSystem setting. Make sure "Windows" is selected, not "Console".

Hans Passant
when i choose Windows instead of Console, i got link error
ufukgun
I'll rub my crystal ball and guess that your main method is named main() instead of WinMain(). Anyhoo, you've found out why you got a console window.
Hans Passant
is there a difference between main() and WinMain()?
ufukgun
Yes, the entry point for native Windows programs is WinMain. Be sure to read Petzold's "Programming Windows".
Hans Passant
+1  A: 

i use that method and it worked

HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, 0);
ufukgun
+1  A: 

Next solution ;)

Env: WixXP x64, msvs 2008, Qt v4.5.3

  1. Set Projects settings/Configuration properties/Linker/System/SubSystem = Windows (/SUBSYSTEM:WINDOWS)

But For x64 there is linker error: LNK2019: unresolved external symbol _WinMain referenced in function _WinMainCRTStartup" To avoid it

    • replace the following code:

    int main(int argc, char argv[]) { QApplication app(argc, argv); // your code }

    by

    int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char*, int nShowCmd) { int argc = 0; QApplication app( argc, 0 );

It works fine for both - Win32 and x64 platforms....

Oleksiy Tarasyuk