Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my Qt 4.5 app open a console window under Windows?

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.

like image 840
Paul Dixon Avatar asked Apr 17 '09 13:04

Paul Dixon


People also ask

What is Qt console Application?

The Qt console is a very lightweight application that largely feels like a terminal, but provides a number of enhancements only possible in a GUI, such as inline figures, proper multi-line editing with syntax highlighting, graphical calltips, and much more. The Qt console can use any Jupyter kernel.

How do I get to the console in Qt?

Start Qt Creator. In the New project dialog, click 'QT4 Console Application' to go to the introduction and project location dialog. The program is build and run. Under Microsoft Windows, a console window appears and shows the text 'Hello world' and waits for a key press to terminate.

How do I run Qt application from terminal?

For console applications, check the Run in terminal check box. To specify the terminal to use on Linux and macOS, select Edit > Preferences > Environment > System. To run with special environment variables set up, select them in the Run Environment section. For more information, see Selecting the Run Environment.


1 Answers

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.

like image 173
Lion Avatar answered Oct 09 '22 05:10

Lion