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. How to handle unknown arguments with QCommandLineParser
Forum Updated to NodeBB v4.3 + New Features

How to handle unknown arguments with QCommandLineParser

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • T Offline
    T Offline
    Thomas Piekarski
    wrote on last edited by
    #1

    Hello,

    I recently needed to parse CLI arguments with QCommandLineParser (Qt 5.15) at two different functions.

    The first function is not aware of the arguments of the second function and it is also the other way around. The second function is also a part of a pre-processed conditional group and is only compiled at Windows.

    What is the preferred way to handle unknown arguments when calling parse() which haven't been added with addOption()?

    The current solution I chose is to ignore the false returned from parse(), but I am not sure if this is the preferred approach.

    How do you handle this situation?

    Is there a way to tell the parser to look only at the arguments added with addOption()? Or maybe did you happen to remove any unknown arguments beforehand. Can you point me to examples at maybe Github implementing such parsing across multiple functions?

    Is there anything new related to command line argument parsing coming in Qt 6.x?

    Thanks in advance.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You can get the unparsed options with QCommandLinParser::unknownOptionNames(). What you do with them is up to you.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • T Offline
        T Offline
        Thomas Piekarski
        wrote on last edited by
        #3

        Thanks, @Christian-Ehrlicher. I wasn't aware of this function, I am going to try to remove all unknown arguments before running parse() and avoid having to ignore a return value on dubious purpose.

        1 Reply Last reply
        0

        • Login

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