Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCommandLineProcessor with negative numbers

QCommandLineProcessor with negative numbers

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 335 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mranger90M Offline
    mranger90M Offline
    mranger90
    wrote on last edited by
    #1

    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();
    }```
    jsulmJ 1 Reply Last reply
    0
    • mranger90M mranger90

      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();
      }```
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mranger90 Does

       app --auto --tilt "-20.2"
      

      work?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by
        #3

        Tried that already, same results

        1 Reply Last reply
        0
        • mranger90M Offline
          mranger90M Offline
          mranger90
          wrote on last edited by
          #4

          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);
          
          
          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved