PDA

View Full Version : Passing Command line arguments to a Qt application in linux



payal
22nd February 2010, 09:31
Hi all,

I have a Qt application for which i have to pass some command line arguements to make it execute..is there any way to set the command line arguements programatically?

How can i achieve this?Anyone, plz help me in this regard.............

Is it possible to mention command line arguements while executing itself?

Regards,
Payal

bender86
22nd February 2010, 09:41
Do you want to execute an application passing some arguments? Look at QProcess::start.
Do you want to get arguments passed to your application? Look at QCoreApplication::arguments.

BalaQT
22nd February 2010, 10:10
yes payal , you can pass arguments from cmd line,

ex

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QStringList args = app.arguments();
if (args.count() != 2)
{

std::cerr << "argument required" << endl;
return 1;
}
myClass m; //ur class
m.test(args[1]); //pass cmd argument as function argument.
return app.exec();
}

hope it helpz
Bala

payal
23rd February 2010, 04:33
Thanks alot Bala..............

I am using QTCreator and i added command line arguements in Project settings.......So now its fine..........

Regards,
Payal