Using QApplication with command line arguments

后端 未结 3 531
臣服心动
臣服心动 2021-01-23 05:54
QApplication::QApplication ( int & argc, char ** argv )

Initializes the window system and constructs an application object

3条回答
  •  無奈伤痛
    2021-01-23 06:47

    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.

提交回复
热议问题