开发者

Hide console of Windows Application

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 St开发者_如何学Cudio 2008)


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")


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

And, change main() to WinMain().


You can get rid of the console by calling:

FreeConsole();


i use that method and it worked

HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, 0);


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.


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


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


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 !


For those of you editing the .vcxproj directly, you want to add a SubSystem with the value Windows to your Link ItemDefinitionGroup as follows:

<ItemDefinitionGroup>
  <Link>
    <SubSystem>Windows</SubSystem>
  </Link>
</ItemDefinitionGroup>


Go to: Projects --> Run and uncheck Run in terminal checkbox


step 1:- Set Properties->Linker->System->SubSystem is "Windows (/SUBSYSTEM:WINDOWS)"
Step 2:- Linker->Advanced-> Entry Point "main"


If all of the properties settings not working above, maybe check to delete 'return app.exec' and 'system("pause")' would help


This worked for me:

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

I needed to run an exe to monitor a file using QFileSystemWatcher so I used this:

CONFIG -= console
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜