PDA

View Full Version : Retrieving command line arguments inside a Qt application



prykHetQuo
14th February 2009, 12:40
We have the code:



#include <QApplication>
#include <QDialog>
#include <QProcess>
#include <cstdlib>

#include "dialog.h"


int main(int argc, char *argv[])
{
QApplication app(argc, argv);

Dialog dialog;

dialog.show();

if(app.exec()!= 0)
return EXIT_FAILURE;
}



How can we retrieve the command line arguments, inside the dialog code (declared in dialog.h as "class Dialog: public QDialog, Ui:: Dialog")?


Thanks.

talk2amulya
14th February 2009, 12:50
add a public function in Dialog class which takes char* argument and pass the argv to it from main function

Lykurg
14th February 2009, 13:19
Hi,

simply use QCoreApplication::arguments () via the qApp pointer but be aware that Qt removes command line arguments that it recognizes!

Lykurg

talk2amulya
14th February 2009, 13:40
thanks for the valuable post man, but what do u mean when u say QT recognizes the argument..what kind of argument can it recognize

Lykurg
14th February 2009, 14:16
Hey, the known arguments are listed at QApplication::QApplication ( int & argc, char ** argv ). There's also the warning.

Lykurg

talk2amulya
14th February 2009, 14:28
oh..so u meant OPTIONS that QApplication recognizes..yeh, in that way its true...thanks for info!