Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-92567

Error in QCommandLineParser documentation example

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2
    • Documentation
    • None
    • All

    Description

      Issue 1: An example in the general documentation for QCommandLineParser (section: How to Use QCommandLineParser in Complex Applications) contains the following bit of code:

      const QCommandLineOption helpOption = parser.addHelpOption();
      ...
      if (parser.isSet(helpOption))
          return CommandLineHelpRequested;
      

      This code has a minor bug, which is that the --help-all option is ignored.

      The only fix I can think of here is, unfortunately, inconsistent with the rest of the coding style, but:

      if (parser.isSet(helpOption) || parser.isSet("help-all"))
          return CommandLineHelpRequested;
      

      Issue 2: The documentation for QCommandLineParser::helpOption() is subtly incorrect. It reads:

      Returns the option instance, which can be used to call isSet().

      However, it does not specify that the actual behavior is that it returns the -help option instance, leaving the -help-all option instance unavailable.

      The fix here would be to add clarity on this point.

      The root issue is that:

      • parser.addHelpOption() adds two options: -help and -help-all.
      • parser.addHelpOption(), however, only returns the QCommandLineOption corresponding to --help.

      Because of this, isSet() on the returned option only indicates if -help was specified, and the only way to check for -help-all is to refer to it by hard-coded name (which may or may not cause an issue with translations, I did not dig into that).

      Whether this is just a documentation error, or a shortcoming in the API, is left as an exercise to the reader. I am treating it as a documentation error here.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            docteam Qt Documentation Team
            jasonc Jason Cipriani
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes