Hide console of Windows Application

2019-01-03 23:34发布

I have a Qt application, and when I run this application, there is a console opening behind it. In development it is nice because i see debug outputs on the console, but when I want to give this executable to the customer there should be no console window. how do I hide it?

(I am using Visual Studio 2008)

11条回答
乱世女痞
2楼-- · 2019-01-04 00:29

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. =)

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-04 00:30

i use that method and it worked

HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, 0);
查看更多
Root(大扎)
4楼-- · 2019-01-04 00:34

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

  2. 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.

查看更多
爷、活的狠高调
5楼-- · 2019-01-04 00:35

In the project build linker options set

/SUBSYSTEM:windows
/ENTRY:mainCRTStartup

Or use the following #pragma in the source file with the int main(...)

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
查看更多
一夜七次
6楼-- · 2019-01-04 00:37

If you use Properties->Linker->System->SubSystem | Windows

And get a linker error.

You can look at Linker->Advanced-> Entry Point

and set the value to the name of your "main" function.

That is your Entry Point becomes, main, if your main function is a "main".

查看更多
登录 后发表回答