Windows – Why does the Qt 4.5 app open a console window under Windows

consolemingwqtqt-creatorwindows

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.

Best Solution

For those who have this issue using CMake under Windows (see Amoo's comment), here's a solution here.

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

add_executable(GuiApplication WIN32 src/main.cpp)

For further details, see the CMake documentation on add_executable and WIN32_EXECUTABLE.