Why does my Qt 4.5 app open a console window under

2019-01-11 09:26发布

I've been playing around with Qt Creator 4.5 under Linux. My application builds just fine under Linux, but if I build in Windows, the app always opens a console window at startup.

Can I stop it doing that?

I'm building using the default MinGW setup, perhaps that is related. If need be I can build with Visual Studio, but I'd like to understand what is happening first...

Edit: I just created a simple test GUI app with Qt Creator under Windows and it didn't exhibit this behaviour. Either this behaviour has occurred because of the way the project was created under linux, or there is something my app does which causes the console window to appear. Will post details when I diagnose it in case it helps someone else.

10条回答
混吃等死
2楼-- · 2019-01-11 09:51

I use cmake instead of qmake. I used set(CMAKE_CXX_FLAGS "-mwindows") seems as though QMAKE_CXXFLAGS +=-mwindows in your .pro file would do the same.

查看更多
疯言疯语
3楼-- · 2019-01-11 09:53

Qt/2009.05/qt/mkspecs/win32-g++
edit file qmake.conf
modify line
QMAKE_LFLAGS_CONSOLE = -Wl,-subsyetem,console
to
QMAKE_LFLAGS_CONSOLE = -Wl,-subsyetem,windows

and modify your ???.pro file (example add new line or space)
and compiling
it`s working ok

查看更多
别忘想泡老子
4楼-- · 2019-01-11 09:56

I think that this is not a solution for this specific answer (besides it is 4 years later), but I think that many people landing in this thread will be looking for this setting:

Projects > Build and Run > Run Settings > Run > [x] Run in terminal

De-select it and run your GUI from QtCreator without an extra Terminal window. Terminal output will be then embedded in the IDE.

查看更多
甜甜的少女心
5楼-- · 2019-01-11 09:57

You will want to make sure the -mwindows switch is provided.

Edit:

alternatively, you can go into your makefile and add this to your linker flags:

-Wl,-subsystem,windows
查看更多
6楼-- · 2019-01-11 09:57

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

查看更多
叛逆
7楼-- · 2019-01-11 09:59

For those who have this issue using CMake, I've found the real solution here. Verified by myself.

In short, you need to add WIN32 to your add_executable() statements:

add_executable(GuiApplication WIN32 src/main.cpp)
查看更多
登录 后发表回答