PDA

View Full Version : QCommandLineOption with argument list



JayKemper
4th March 2020, 00:59
I'm trying to parse the following command line input:



./qtProgram --arguments first second third


I've looked at the documentation for QCommandLineParser and the provided example, but they only address when the command line argument has one value.

There is a QCommandLineParser function called "values" that returns a QStringList, which looked promising, but it only returns a list of one (and it's "first"). How do I set up the QCommandLineOption to pull all of them into a QStringList?



...

QCommandLineOption argumentOption(QStringList() << "a" << "arguments",
"Parse the following arguments <arguments>.",
"none");
parser.addOption(argumentOption);

...

QStringList argumentList = parser.values(argumentOption); // Size is one, value is "first"

smyk
4th March 2020, 09:11
I think QCommandLineParser::values() (https://doc.qt.io/qt-5/qcommandlineparser.html#values-1) may work, if you launch your app with:

./qtProgram -a first -a second -a third
Otherwise you should use

./qtProgram -a "first second third"
and split "first second third" into a QStringList