Hide console of Windows Application

WindowsVisual StudioQtConsoleHide

Windows Problem Overview


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)

Windows Solutions


Solution 1 - Windows

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

Solution 2 - Windows

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

Solution 3 - Windows

You can get rid of the console by calling:

FreeConsole();

Solution 4 - Windows

i use that method and it worked

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

Solution 5 - Windows

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

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

Solution 6 - Windows

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

Solution 7 - Windows

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

Solution 8 - Windows

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 !

Solution 9 - Windows

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>

Solution 10 - Windows

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

Solution 11 - Windows

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

Solution 12 - Windows

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

Solution 13 - Windows

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionufukgunView Question on Stackoverflow
Solution 1 - WindowsdatenwolfView Answer on Stackoverflow
Solution 2 - WindowsHans PassantView Answer on Stackoverflow
Solution 3 - WindowsDaniel MunozView Answer on Stackoverflow
Solution 4 - WindowsufukgunView Answer on Stackoverflow
Solution 5 - WindowsOleksiy TarasyukView Answer on Stackoverflow
Solution 6 - WindowsWildcatView Answer on Stackoverflow
Solution 7 - WindowsGuestView Answer on Stackoverflow
Solution 8 - WindowsAndy MView Answer on Stackoverflow
Solution 9 - WindowsDogmatixedView Answer on Stackoverflow
Solution 10 - WindowsArtem ZaytsevView Answer on Stackoverflow
Solution 11 - WindowsMilind MoreyView Answer on Stackoverflow
Solution 12 - WindowsBattery Eyes WUWView Answer on Stackoverflow
Solution 13 - WindowsFestus FasholaView Answer on Stackoverflow