Hide console of Windows Application
Solution 1
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 2
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 3
You can get rid of the console by calling:
FreeConsole();
Solution 4
i use that method and it worked
HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, 0);
Solution 5
Next solution ;)
Env: WixXP x64, msvs 2008, Qt v4.5.3
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.
ufukgun
:) c++ java openGL delta3D osg glsl qt equalizer openAL ...
Updated on February 12, 2020Comments
-
ufukgun over 4 years
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)
-
Veeti over 14 yearsThe actual Visual Studio project is created using the configuration parameters in the QMake project file, so this could very well be the cause.
-
Andy M over 14 yearsErm, 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 over 14 yearsI 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.lib in VCProj Properties-> Links Edition -> Entry -> Additionnal Dependencies
-
Andy M over 14 yearsAnd it looks like it's the final solution :) lists.trolltech.com/qt-interest/2005-12/thread00170-0.html
-
ufukgun over 14 yearsis there a difference between main() and WinMain()?
-
datenwolf almost 13 yearsThis method will prevent the program from getting parameters from the command line. Very, very bad idea. -1. If you want to do it correctly, tokenize the string you receive fin the third parameter of WinMain. And yes, there are plenty of Windows programs that interpret command line parameters. For example the "Printing" context menu in Windows Explorer starts a program with command line parameters.
-
Cray over 12 yearsImo the best and to-the-point answer, dealing with both the subsystem part and the different entry points part. Small unicode hint: if you compile with unicode and have wmain as opposed to main, comment should be "/ENTRY:wmainCRTStartup".
-
Cray over 12 yearsdatenwolf, They are still there using __argv and __argc macros (at least in MSVC) or GetCommandLine/CommandLineToArgv winapi function.
-
Jan Turoň over 12 yearsYou may also set the entry point of the project to standard
main()
in Properties -> Linker -> Advanced -> Entry point -
datenwolf about 12 years@Cray: WCHAR is not Unicode. If you're using real Unicode with the appropriate libraries like ICU, normal mainCRTStrartup works just fine.
-
Cray about 12 yearsSure, however I was talking about the compiler option (ie, "compile with unicode"). They are actually calling it "Use Unicode Character Set".
-
Guy Joel McLean about 11 yearsThis solution worked for me and my OpenGL application. I started the project months ago as a console application, using the console window for early debugging. Starting the project again as a windows application and pasting all of the files over, as well as re-entering all of the library dependencies just seemed tedious.
-
datenwolf about 11 years@GuyJoelMcLean: Pro-Tipp: If you need a console later on for debugging you can use AllocConsole msdn.microsoft.com/en-us/library/windows/desktop/…
-
Tomáš Zato over 9 yearsThe problem is that when I turn the program in
Windows
it doesn't terminate, even if I fix themain
/WinMain
issue. -
nwp over 9 yearsIf you start the program from command line the command line will disappear.
FreeConsole
does not have that issue. -
John Neuhaus almost 9 yearsIn VS 2010 the pragma didn't work for me. I had to set the two settings through project properties, removed _CONSOLE from the preprocessor. Then I rebuilt, and it worked perfectly.
-
Nic about 6 years@JanTuroň How? What option do we put in that field? It's a string field and I've tried a wide variety of solutions, none of which work.
-
Jan Turoň about 6 years@NicHartley back then in 2008 it should be a selectbox. Perharps there are other settings in config. Could you ask another question and provide step by step setup to reproduce that?
-
alexpanter over 4 yearsThis should be the accepted answer. E.g. if you are developing with CMake on Windows, this is the only option. Also, it is portable to other windowing systems, such as GLFW, SDL, ...
-
Noah.Ehrnstrom almost 4 yearsThis helped out very much!
-
Superior over 3 yearsYou'll have to
#include <Windows.h>
for that -
Tayab about 3 yearsThis solved the issue for me. Many thank :))
-
Radim Cernej over 2 yearsWorked for me. Qt6, Win10, MSVC2019, amd64 build.