Results 1 to 2 of 2

Thread: QCommandLineOption with argument list

  1. #1
    Join Date
    Jun 2015
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QCommandLineOption with argument list

    I'm trying to parse the following command line input:

    Qt Code:
    1. ./qtProgram --arguments first second third
    To copy to clipboard, switch view to plain text mode 

    I've looked at the documentation for QCommandLineParser and the provided example, but they only address when the command line argument has one value.

    There is a QCommandLineParser function called "values" that returns a QStringList, which looked promising, but it only returns a list of one (and it's "first"). How do I set up the QCommandLineOption to pull all of them into a QStringList?

    Qt Code:
    1. ...
    2.  
    3. QCommandLineOption argumentOption(QStringList() << "a" << "arguments",
    4. "Parse the following arguments <arguments>.",
    5. "none");
    6. parser.addOption(argumentOption);
    7.  
    8. ...
    9.  
    10. QStringList argumentList = parser.values(argumentOption); // Size is one, value is "first"
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    9
    Thanks
    1
    Platforms
    Unix/X11

    Default Re: QCommandLineOption with argument list

    I think QCommandLineParser::values() may work, if you launch your app with:
    Qt Code:
    1. ./qtProgram -a first -a second -a third
    To copy to clipboard, switch view to plain text mode 
    Otherwise you should use
    Qt Code:
    1. ./qtProgram -a "first second third"
    To copy to clipboard, switch view to plain text mode 
    and split "first second third" into a QStringList

Similar Threads

  1. Question on proper use of QCommandLineOption?
    By TorAn in forum Qt Programming
    Replies: 12
    Last Post: 13th November 2016, 01:30
  2. Llarge set of data in QML List view/C++ List model
    By ashwasimha in forum Qt Quick
    Replies: 4
    Last Post: 26th October 2016, 07:50
  3. Replies: 4
    Last Post: 14th June 2012, 23:33
  4. Replies: 1
    Last Post: 23rd April 2011, 17:33
  5. List View with sections for alphabetialy sorted list
    By woodtluk in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2010, 11:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.