Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QCommandLineParser: increase variable value



  • Hello!
    Example from QCommandLineParser

    QCommandLineParser parser;
    // A boolean option with a single name (-p)
    QCommandLineOption showProgressOption("p", QCoreApplication::translate("main", "Show progress during copy"));
    parser.addOption(showProgressOption);
    // Process the actual command line arguments given by the user
    parser.process(app);
    bool force = parser.isSet(forceOption);
    

    How can I process command line parsing if I use several -p, e.g. -pppp?
    I will save value to integral variable, result shold have value 1 if I pass one -p and value 4 if I pass -pppp.
    Thank you.



  • @debian said in QCommandLineParser: increase variable value:

    How can I process command line parsing if I use several -p, e.g. -pppp

    I'm not sure QCommandLineParser will provide that functionality. Indeed, I'd say that -p is quite a different option from -pppp (or any combination in between), at least you want to identify both, so I'd rather add all the required combinations and process them accordingly. Pseudo-code:

    QCommandLineOption showProgressOption("p", QCoreApplication::translate("main", "Show progress during copy"));
    parser.addOption(showProgressOption);
    ...
    QCommandLineOption showVeryVerboseProgressOption("pppp", QCoreApplication::translate("main", "Show very verbose progress during copy"));
    parser.addOption(showVeryVerboseProgressOption);
    

    later on:

    ...
    if (showProgressOption) {
        // show progress...
    }
    if (showVeryVerboseProgressOption) {
        // show very detailed progress...
    }

Log in to reply