QCommandLineProcessor with negative numbers
Solved
General and Desktop
-
Trying to get QCommandLineParser to work with a negative floating point argument.
For example the following code wants to parse a command line of: app --auto --tilt -20.2
But QCP is trying to use the "-20.2" as an argument and complains.int main(int argc, char *argv[]) { QApplication app(argc, argv); QCommandLineParser parser; parser.setApplicationDescription("Projection Reconstructor " + QString("1.0")); // Run in auto mode (-a, --auto) as opposed to interactive QCommandLineOption autoReconstructionOption( QStringList() << "a" << "auto", QCoreApplication::translate("main", "Operate in automatic mode.")); parser.addOption(autoReconstructionOption); QCommandLineOption tiltAngleOption( QStringList() << "t" << "tilt", QCoreApplication::translate("main", "floating point tilt angle.")); parser.addOption(tiltAngleOption); parser.addHelpOption(); parser.addVersionOption(); parser.process(app); const bool runAutoMode = parser.isSet(autoReconstructionOption); double tiltAngleValue = 0.0; if (parser.isSet(tiltAngleOption)) { bool convertOk; const double angleFromCommandline = parser.value(tiltAngleOption).toDouble(&convertOk); if (convertOk) { tiltAngleValue = angleFromCommandline; } } qDebug() << "runAutoMode = " << runAutoMode << "Tilt Angle" << tiltAngleValue; PtoVMain w(runAutoMode); w.show(); return app.exec(); }```
-
Trying to get QCommandLineParser to work with a negative floating point argument.
For example the following code wants to parse a command line of: app --auto --tilt -20.2
But QCP is trying to use the "-20.2" as an argument and complains.int main(int argc, char *argv[]) { QApplication app(argc, argv); QCommandLineParser parser; parser.setApplicationDescription("Projection Reconstructor " + QString("1.0")); // Run in auto mode (-a, --auto) as opposed to interactive QCommandLineOption autoReconstructionOption( QStringList() << "a" << "auto", QCoreApplication::translate("main", "Operate in automatic mode.")); parser.addOption(autoReconstructionOption); QCommandLineOption tiltAngleOption( QStringList() << "t" << "tilt", QCoreApplication::translate("main", "floating point tilt angle.")); parser.addOption(tiltAngleOption); parser.addHelpOption(); parser.addVersionOption(); parser.process(app); const bool runAutoMode = parser.isSet(autoReconstructionOption); double tiltAngleValue = 0.0; if (parser.isSet(tiltAngleOption)) { bool convertOk; const double angleFromCommandline = parser.value(tiltAngleOption).toDouble(&convertOk); if (convertOk) { tiltAngleValue = angleFromCommandline; } } qDebug() << "runAutoMode = " << runAutoMode << "Tilt Angle" << tiltAngleValue; PtoVMain w(runAutoMode); w.show(); return app.exec(); }```
-
Got it, had to another argument to the option
QCommandLineOption tiltAngleOption( QStringList() << "t" << "tilt", QCoreApplication::translate("main", "floating point tilt angle."), QCoreApplication::translate("main", "angle value")); parser.addOption(tiltAngleOption);