Solved How to create a console application with command line arguments in Qt?
-
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
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. -
@Guerrian
Qt has for this a adequately named class QCommandLineParserMight be helpful 😉
-
@Guerrian hi
for (int i = 1; i < argc; i++) { qDebug() << "param" << i << " is " << argv[i]; }
-
Hi,
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