how to enable an app to be executed in GUI mode and console mode
Hi guys,
I made an App with GUI. But now I would like to manage the options in the command line.
Examaple, if I execute the MyApp.exe without parameters (or by clicking the icon), then It should launch the Main window, etc.
But If I execute form the command line something like MyApp.exe -version, I would like to get only the version, without launching the App.
I modified the .pro file and added
in order to return the version with a cout sentence in the main.cpp.
But now if I execute the app without any argument, the console is launched at the same time of the main window. So the console keeps behind the main window.
What am I missing? There is another way to do that?
Thanks in advance!
Re: how to enable an app to be executed in GUI mode and console mode
This should be very easy:
Code:
int main(int argc, char *argv[])
{
if (argv[1] == "-version") {
printf("Version");
exit 0;
}
...
return a.exec();
}
Re: how to enable an app to be executed in GUI mode and console mode
This is not the problem. I've made alreadyt the code, the problem is that, If I configure the .pro file as CONFIG += console. Then when I start the app with no arguments, it lauches the console and the main window as well. I this case I dont want to see thjie console, just the main window.
Re: how to enable an app to be executed in GUI mode and console mode
Don't add config += console
Re: how to enable an app to be executed in GUI mode and console mode
If I dont add config+=console, when I rund the program from the command promp with the -version argument, then nothing appears.
Re: how to enable an app to be executed in GUI mode and console mode
Then I don't know. Is this even possible in Windows?
Here you have a GUI application where you can perfectly add an about dialog with the version number.
Why do you want to print that in the console?
Re: how to enable an app to be executed in GUI mode and console mode
I don't think that the behavior you want is possible under Windows platform...
Re: how to enable an app to be executed in GUI mode and console mode
I want to print it in the console because an external software will made some checks about the version. So the real user will run the app just from the icon (without parameters, ) but the other checking software will run it with the versiona argument, in order to get the version and make some checks.
Re: how to enable an app to be executed in GUI mode and console mode
Nice but not possible on Windows. Though you can always try with IPC, if you have the sources of the other software. :)
Re: how to enable an app to be executed in GUI mode and console mode
Isn't it possible to set a version number for an exe just like you do for a DLL?
Re: how to enable an app to be executed in GUI mode and console mode
That sounds a bit complicate. Thanks anyways
Re: how to enable an app to be executed in GUI mode and console mode
You can use AllocConsole(). If your app already has a console it'll fail, otherwise it'll open a new console and set the appropriate handles for you (by default, GUI applications do not have a console)
You can then use GetStdHandle(STD_OUTPUT_HANDLE) to get a handle to your console to which you can write to using WriteFile() or WriteConsole().
http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx