1 Attachment(s)
Switching between console and GUI on startup
I'm trying to add console support to my already working application. So I get in the main to add some switch support to the command line but it is not poping any command line when entering the right switch. Here's a little main In crafted to try this coexistence :
Code:
#include <QApplication>
#include <QtGui>
// for cout
#include <iostream>
using namespace std;
int main( int argc, char** argv )
{
bool console = false;
if ( argc > 1 )
{
// Check if user selected console mode.
for ( int i=1; i<argc; ++i )
{
if ( !strcmp( argv[i], "-console" ) )
{
console = true;
break;
}
}
}
if ( console )
{
// This is not working.
cout << "Console Mode" << endl;
// Try to write a file.
QFile myFile
( "C:\\Temp\\Test.txt" );
stream << "Console is working but not showing";
return 0;
}
else
{
label->show();
return app.exec();
}
}
The file gets written but I don't get any output to the console. I added the switch to tell it is a command line app and I can see the output however, I will get a console even if I'm in GUI mode.
How can I achieve an application that can be executed in either mode ?
Another question, does my -console switch is already used by Qt ?
Re: Switching between console and GUI on startup
How about:
Code:
#include <QApplication>
int main(int argc, char **argv){
bool gui = true;
for(int i=1; i<argc; i++)
if(!strcmp(argv[i], "--console")){
gui = false;
break;
}
//...
return app.exec();
}
Re: Switching between console and GUI on startup
I feel so dumb now ... Big RTFM for me lol
Re: Switching between console and GUI on startup
I may have felt dumb but it's still not working as expected, application don't output to console but is writing the file. So my question remains ...
Re: Switching between console and GUI on startup
IMO the problem might be in windows' subsystems. You are using win32 subsystem now, but console applications use different one. You should be able to find some info about this in MSDN (most likely it's a matter of setting right linker flags).