Retrieving command line arguments inside a Qt application
We have the code:
Code:
#include <QApplication>
#include <QDialog>
#include <QProcess>
#include <cstdlib>
#include "dialog.h"
int main(int argc, char *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.
Re: Retrieving command line arguments inside a Qt application
add a public function in Dialog class which takes char* argument and pass the argv to it from main function
Re: Retrieving command line arguments inside a Qt application
Hi,
simply use QCoreApplication::arguments () via the qApp pointer but be aware that Qt removes command line arguments that it recognizes!
Lykurg
Re: Retrieving command line arguments inside a Qt application
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
Re: Retrieving command line arguments inside a Qt application
Hey, the known arguments are listed at QApplication::QApplication ( int & argc, char ** argv ). There's also the warning.
Lykurg
Re: Retrieving command line arguments inside a Qt application
oh..so u meant OPTIONS that QApplication recognizes..yeh, in that way its true...thanks for info!