QApplication::QApplication ( int & argc, char ** argv )
Initializes the window system and constructs an application object
The arguments passed in the constructor are later accessible through the static method
QStringList QCoreApplication::arguments()
. By this, command line arguments can be handled everywhere in your code.
Continue reading that documentation. The set of flags QApplication
acts on is listed there.
Try for example:
./qt -style=windows
The arguments that QApplication
doesn't deal with are simply left alone. The ones it does process are removed (which is why that function takes non-const arguments).
The suggestion about using QCoreApplication is only recommended of you have a console application. If you are using a QApplication instead, and want to access command-line arguments from inside a QWidget, you can do it with the global pointer qApp:
Here you can find the documentation from Nokia, or here from qt-project.org . In the documentation browser of Qt Creator I couldn't find it, so it is at best not that easily accessible.
so you can find:
int my_argc = qApp->arguments().count();
QString my_argv_0 = qApp->arguments.at(0);
...
and so on.
I know this question is old, but took me some time to find a way to do it from within my Main Window, so hope this helps someone else.