ufukgun
ufukgun

Reputation: 7209

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 Studio 2008)

Upvotes: 69

Views: 132373

Answers (13)

Battery Eyes WUW
Battery Eyes WUW

Reputation: 9

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

Upvotes: 0

Milind Morey
Milind Morey

Reputation: 2116

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

Upvotes: -1

Guest
Guest

Reputation: 61

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

Upvotes: 6

Festus Fashola
Festus Fashola

Reputation: 161

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

Upvotes: -1

Hans Passant
Hans Passant

Reputation: 941218

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

Upvotes: 71

Artem Zaytsev
Artem Zaytsev

Reputation: 1695

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

Upvotes: 0

Dogmatixed
Dogmatixed

Reputation: 794

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>

Upvotes: 2

Oleksiy Tarasyuk
Oleksiy Tarasyuk

Reputation: 117

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.

Upvotes: 10

Daniel Munoz
Daniel Munoz

Reputation: 1965

You can get rid of the console by calling:

FreeConsole();

Upvotes: 24

datenwolf
datenwolf

Reputation: 162164

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

Upvotes: 160

ufukgun
ufukgun

Reputation: 7209

i use that method and it worked

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

Upvotes: 14

Wildcat
Wildcat

Reputation: 8870

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

Upvotes: 6

Andy M
Andy M

Reputation: 6065

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 !

Upvotes: 4

Related Questions