DayAndNight
DayAndNight

Reputation: 307

Qt5 opens console with gui applications

I use Qt5.2 (git) with MSVC13 on Windows. If I build any application (even the templates) it always opens in a cmd.exe window. I tried different Qt versions and different compilers (even MinGW), but I always have the same problem. If however, I start the application using the green play button in QtDesigner it opens without a cmd window. As suggested here I tried "CONFIG -= console" with no effect. Also I dont use testlib. In my qmake.conf I see the line "QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS"

Does this depend on the dll files I put in the application directory? QtDesigner does not copy any dlls to the build folder, however it sets some environment variables. To run the application from a separate folder I copy the corresponding dlls from the Qt lib folder into the applications exe folder.

Any ideas for this strange behaviour?

Upvotes: 2

Views: 4224

Answers (3)

DayAndNight
DayAndNight

Reputation: 307

Ok, this took a while, but i finally found the solution here: Hide console of Windows Application

I had to replace the main entry function:

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 );
 }

Thanks everybody!

Upvotes: 2

Kirell
Kirell

Reputation: 9818

In MSVC 2013 go to your project properties/ linker and change from:

/SUBSYSTEM:CONSOLE

To:

/SUBSYSTEM:WINDOWS

It worked for me.

TODO

Upvotes: 3

Thomas Ayoub
Thomas Ayoub

Reputation: 29451

Is the checkbox run in terminal checked?

enter image description here

Upvotes: 0

Related Questions