How to create a console application with command line arguments in Qt?
-
wrote on 28 Jan 2020, 13:39 last edited by
I have looked at this online and seen various approaches such as using QApplication or QCoreApplication. I would like to use Qt objects for the application and parse the command line. For example to parse a command line such as:
myapp -foo bar -qaz 10
Which approach is best?
-
I have looked at this online and seen various approaches such as using QApplication or QCoreApplication. I would like to use Qt objects for the application and parse the command line. For example to parse a command line such as:
myapp -foo bar -qaz 10
Which approach is best?
wrote on 28 Jan 2020, 13:43 last edited by JonB@Guerrian
You can pick whichever kind of QApplication is best for your program, and you can access command-line arguments either viaQCoreApplication::arguments()
(if you don't need a GUI) or other Qt classes, or from the C++main(argc, argv)
as you please. -
I have looked at this online and seen various approaches such as using QApplication or QCoreApplication. I would like to use Qt objects for the application and parse the command line. For example to parse a command line such as:
myapp -foo bar -qaz 10
Which approach is best?
@Guerrian
Qt has for this a adequately named class QCommandLineParserMight be helpful 😉
-
I have looked at this online and seen various approaches such as using QApplication or QCoreApplication. I would like to use Qt objects for the application and parse the command line. For example to parse a command line such as:
myapp -foo bar -qaz 10
Which approach is best?
-
I have looked at this online and seen various approaches such as using QApplication or QCoreApplication. I would like to use Qt objects for the application and parse the command line. For example to parse a command line such as:
myapp -foo bar -qaz 10
Which approach is best?
wrote on 28 Jan 2020, 13:48 last edited by Pl45m4Hi,
there is a
QCommandLineParser
-class. (https://doc.qt.io/qt-5/qcommandlineparser.html#details)
Have a look at this.Edit:
Damn, I'm typing too slow... :) @J-Hilk
1/5