如何保持我的Qt C ++程序在Windows中打开控制台? [英] How do I keep my Qt C++ program from opening a console in Windows?
问题描述
我在Qt Creator中创建一个应用程序,使用cmake和MinGW作为编译器。我看到这个问题被其他人回答,但他们使用常规的Qt项目与.pro文件,而我使用CMakeLists.txt文件。所以这些帖子对我没有帮助。
I'm making an application in Qt Creator, with cmake and MinGW as compiler. I've seen this question being answered for other people, but they used regular Qt projects with .pro files, while I use a CMakeLists.txt file. So these posts were of no help to me.
问题是,我的应用程序在启动时打开一个控制台,像往常一样,关闭这个控制台将关闭应用程序。我想保持应用程序不打开控制台,这样对于不需要任何调试信息等的人来说更加用户友好。
The problem is that my application opens a console when booted, and as usual, closing this console will close the application as well. I want to keep the application from opening a console, so that it is more user-friendly for people who don't need any debug information and such.
推荐答案
您很可能在CMakeLists.txt中有一行如下:
You will most likely have a line such as the following in your CMakeLists.txt:
ADD_EXECUTABLE(exename ....)
当然这些点是进一步的参数。将此更改为:
where of course the dots are further arguments. Change this to:
ADD_EXECUTABLE(exename [WIN32] ...)
来指定它是一个Win32应用程序而不是控制台应用程序。
to specify that it's a Win32 application and not a console application.
或者,如在CMAKE网站上如果 WIN32
给定属性 WIN32_EXECUTABLE
设置在创建的目标上。当设置WIN32_EXECUTABLE时,它将构建可执行文件在Windows上有一个WinMain入口点。
Or, as can be found on the CMAKE website "If WIN32
is given the property WIN32_EXECUTABLE
will be set on the target created." And when WIN32_EXECUTABLE is set it will "Build an executable with a WinMain entry point on windows."
这篇关于如何保持我的Qt C ++程序在Windows中打开控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!