View Full Version : How to create single exe for Console & GUI mode

10th June 2009, 13:43
Hi All,

How can I create single exe for Console and Gui mode in Qt ???

Thanks in advance.

10th June 2009, 14:53
interpreted argv and if the user gives you a console flag, don't call show() on your mainwindow.

10th June 2009, 14:58
Hi ,

Thanks for your reply.
Can you please elaborate it with small example ,I searched a lot in net, but didn't get much help.

My requirement is just by setting some flag in config file(which is outside the application) application should be able to change the mode(GUI/Console) dynamically.

Once again thanks.

PS: I am using Qt4.3.2.

10th June 2009, 20:40

void main(int argc, char *argv[])
bool isConsole = false
for(int i=0;i<argc;i++)
if ("console" == argv[i])
isConsole = true;

QApplication app(argc, argv);
MainWindow mainWin;
if (!isConsole)
return app.exec();

./myapp console

Or you can change... Switch from Gui to console application, just hide the mainwindow.

11th June 2009, 08:20
This will possibly not work and GUI thread will block the Console window, because my program Linker>>system>>subsystem has Windows (/SUBSYSTEM:WINDOWS) value not "Console". I want to do this dynamically with progam.

I think I am not clear.
When you create one Qt Core application and try to print any thing using operator Cout or fgets() it sends the output to Console window(command prompt) and you can see the output there, but if you use Qt(GUI) mode you can't see command prompt .This is because GUI thread blocks it .
I know this can be invoked using QProcess::startdetached("Cmd.exe"),but by using this I need to change the whole code ,I mean I can't simply send/recieve the output to console using cout/fgets() and all this can be done if I use console mode of Qt (Qt-Core).That's the reason I want two mode in my single executable so that user can operate on either mode just by some configuration settings.

I hope I have explain the problem domain.

I have gone through various links about this but nothing works for me