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. [SOLVED] QCommandLineParser - override showHelp() and showVersion()
QtWS25 Last Chance

[SOLVED] QCommandLineParser - override showHelp() and showVersion()

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.8k Views
  • 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.
  • sahadumS Offline
    sahadumS Offline
    sahadum
    wrote on last edited by
    #1

    Hi,

    I started using QCommandLineParser for a GUI app on MS Windows. After launching the app from a console window I couldn't see any output in the console window. This is a MS Windows specific problem.

    For my GUI app I want to use a MessageBox with the version and help text from the parser. The output of the showHelp() and showVersion() functions is printed to the console via fprintf(...). After the fprintf() call there is an exit() call.

    I inherit my on class from QCommandLineParser and override the showVersion() and showHelp() member functions to use QMessageBox instead of the fprintf(). But these functions are not declared virtual in Qt5.4 and for that the internal member functions of QCommandLineParse didn't call my new functions. Is there a special reason why these functions are not declared virtual?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      For Qt internal design related question, you should rather try the "interest mailing list":http://lists.qt-project.org/mailman/listinfo/interest . You'll find there Qt's developers/maintainers (this forum is more user oriented)

      Did you took a look at the "QCommandLineParse in Complex Applications":http://doc.qt.io/qt-5/qcommandlineparser.html#how-to-use-qcommandlineparser-in-complex-applications part ? It shows how do use QMessageBox and QCommandLineParser together

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • sahadumS Offline
        sahadumS Offline
        sahadum
        wrote on last edited by
        #3

        Hi,

        thanks for your help. I searched the net, read forum, doc and the source code but missed that "Complex Application" example.

        My fault was to use parser.process(...) instead of parser.parse(...). Only process() uses the showHelp() and showVersion() functions which then use fprintf().
        For GUI apps, parse() and then errorText() and helpText() should be used to get the output. Like the example shows :)

        With this in mind it is not necessary to declare the showXXX() functions as virtual anymore.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Since there's a bit of moving right now, double check that the documentation you're reading online matches the version you are using. The current correct link is doc.qt.io

          Happy coding !

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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