c++ - How to use QCommandLineParser for arguments with multiple params? -


I wonder, how can I use multiple- or sub-logic with it? For example:

  / home / my_app - my_option_with_two_params first_perm_sleep_image - the-ultimate-of-my-choice-ultimate?    

Try it which is -i / my / include / Path1 -i / My / include / path2 :

  --my_option_with_two_params first_update - my_option_with_two_params second_param  

... and then you can do the values Use to:

QStringList QCommandLineParser :: Value (Const. Custring and Option No.) Const

One of the values ​​found for the given option name The list gives OptionName or an empty list if not found.

The name provided can be any long or short name for any option that was added with addOption ().

Here you can find a simple test case that works:

main.cpp

  #include & lt ; QCoreApplication & gt; # Include & lt; QCommandLineParser & gt; # Include & lt; QCommandLineOption & gt; # Include & lt; QDebug & gt; Int main (int argc, char * argv []) {QuakeAppleApp (argc, argv); QCoreApplication :: setApplicationName ("Multi-Man-Program"); QCoreApplication :: setApplicationVersion ("1.0"); QCommandLineParser Parser; Parser.setApplicationDescription ("Test Assistant"); Parser.addHelpOption (); Parser.addVersionOption (); QCommandLineOption targetDirectoryOption (QStringList () & lt; "t" & lt; "target-directory", QCoreApplication :: Translation ("Main", "Copy all source files to & lt; Directory & gt;") , QCoreApplication :: Translate ("Main", "Directory")); Parser.addOption (targetDirectoryOption); Parser.process (app); QDebug () & lt; & Lt; Parser.values ​​(targetDirectoryOption); Return 0; }  

main.pro

  template = app target = chief qt = core source + = main.cpp  

Build and Run

  QMake & amp; Run  

and output

  ./ main -t foo -t times -> ("Foo", "bar") ./main -t foo bar - & gt; ("Foo")  

Comments