This is already handled - the syntax you propose doesn't quite fit QCommandLineParser
. Either use -p 5000,7000,8000
or -p "5000 7000 8000"
. All those ports will be the value of the port option, and you can then separate them with split(QRegularExpression("[, ]"), Qt::SkipEmptyParts)
(that's QString::split
). E.g.:
auto ports = parser.value("target-port")
.split(QRegularExpression("[, ]"), Qt::SkipEmptyParts);
for (auto &portStr : ports) {
bool ok = false;
int port = portStr.toInt(&ok);
if (!ok) continue;
// use port value here
}
Alternatively, since the Qt source code is available, you could copy the command line parser source into your project, rename the class, and extend it to support the original syntax you had in mind.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…