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. Empty values of command line options
Forum Updated to NodeBB v4.3 + New Features

Empty values of command line options

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 335 Views 1 Watching
  • 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.
  • D Offline
    D Offline
    Dmitriano
    wrote on last edited by Dmitriano
    #1

    The value of databasePathOption command line option in the code below is always empty:

    int main(int argc, char* argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QGuiApplication app(argc, argv);
        QCoreApplication::setApplicationVersion("1.0");
        QCoreApplication::setApplicationName("MyApp");
    
        QCommandLineParser parser;
        parser.setApplicationDescription("My App");
        parser.addHelpOption();
        parser.addVersionOption();
        QCommandLineOption databasePathOption(QStringList() << "x" << "db123", QCoreApplication::translate("main", "Program database file path."));
        parser.addOption(databasePathOption);
        parser.process(app);
    
        QString val = parser.value(databasePathOption);
        qDebug() << "db=" << val;
       ...
    }
    

    I start the program with the following arguments:

    --db123 "asdf"
    

    but it prints an empty string.

    What did I do wrong?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From the documentation, you are missing the valueName parameter.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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