[SOLVED] QCommandLineParser - override showHelp() and showVersion()
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?
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
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.
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 !