隐藏 Windows 应用程序的控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2139637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide console of Windows Application
提问by ufukgun
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?
我有一个 Qt 应用程序,当我运行这个应用程序时,它后面会打开一个控制台。在开发中,这很好,因为我在控制台上看到调试输出,但是当我想将此可执行文件提供给客户时,应该没有控制台窗口。我该如何隐藏它?
(I am using Visual Studio 2008)
(我使用的是 Visual Studio 2008)
回答by datenwolf
In the project build linker options set
在项目构建链接器选项中设置
/SUBSYSTEM:windows
/ENTRY:mainCRTStartup
Or use the following #pragmain the source file with the int main(...)
或者在源文件中使用以下#pragmaint main(...)
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
回答by Hans Passant
It sounds like your linker configuration is incorrect. Right-click the project, Properties, Linker, System, SubSystem setting. Make sure "Windows" is selected, not "Console".
听起来您的链接器配置不正确。右键单击项目、属性、链接器、系统、子系统设置。确保选择了“Windows”,而不是“控制台”。
And, change main() to WinMain().
并且,将 main() 更改为 WinMain()。
回答by Daniel Munoz
You can get rid of the console by calling:
您可以通过调用来摆脱控制台:
FreeConsole();
回答by ufukgun
i use that method and it worked
我使用这种方法并且它有效
HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, 0);
回答by Oleksiy Tarasyuk
Next solution ;)
下一个解决方案;)
Env: WixXP x64, msvs 2008, Qt v4.5.3
环境: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 ); }
设置项目设置/配置属性/链接器/系统/子系统 = Windows (/SUBSYSTEM:WINDOWS)
但是对于 x64 有链接器错误:LNK2019: unresolved external symbol _WinMain referenced in function _WinMainCRTStartup" 为了避免它
替换以下代码:
int main(int argc, char *argv[]) { QApplication app(argc, argv); // your code* }
经过
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.
它适用于 Win32 和 x64 平台。
回答by Guest
If you use Properties->Linker->System->SubSystem| Windows
如果使用属性->链接器->系统->子系统| 视窗
And get a linker error.
并收到链接器错误。
You can look at Linker->Advanced-> Entry Point
你可以看看Linker-> Advanced-> Entry Point
and set the value to the name of your "main" function.
并将值设置为“main”函数的名称。
That is your Entry Point becomes, main, if your main function is a "main".
如果您的主要功能是“主要”,那么您的入口点将变为主要。
回答by Wildcat
May be the better option will be not to simply remove (as Andy M suggested) but edit *.pro file adding something like
可能更好的选择不是简单地删除(如 Andy M 建议的那样)而是编辑 *.pro 文件添加类似的东西
CONFIG(debug, debug|release) {
CONFIG *= console
}
else {
CONFIG -= console
}
In debug you can see console window but not in release. I like it. =)
在调试中,您可以看到控制台窗口,但在发布中看不到。我喜欢。=)
回答by Andy M
I would suggest to check the presence of the following line in your .PRO file :
我建议检查您的 .PRO 文件中是否存在以下行:
CONFIG += console
If you can find it, remove it ! It should fix your issue !
如果你能找到它,删除它!它应该可以解决您的问题!
Hope it helps !
希望能帮助到你 !
回答by Dogmatixed
For those of you editing the .vcxproj directly, you want to add a SubSystem
with the value Windows
to your Link
ItemDefinitionGroup
as follows:
对于那些直接编辑.vcxproj,要添加一个SubSystem
与价值Windows
,以你的Link
ItemDefinitionGroup
,如下所示:
<ItemDefinitionGroup>
<Link>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
回答by Artem Zaytsev
Go to: Projects --> Run
and uncheck Run in terminal
checkbox
转到:Projects --> Run
并取消选中Run in terminal
复选框