Skip to content

Switch to QCommandLineParser. #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged

Switch to QCommandLineParser. #316

merged 1 commit into from
Jun 20, 2025

Conversation

jtjbrady
Copy link
Contributor

I was bored. @dfaure-kdab you only have yourself to blame for this pull request:

#224 (comment)

@jtjbrady jtjbrady marked this pull request as draft June 19, 2025 21:23
@jtjbrady jtjbrady marked this pull request as ready for review June 20, 2025 09:05
Copy link
Member

@dfaure-kdab dfaure-kdab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I like what you do when you're bored ;)


KWSDL::Compiler compiler;
#if !defined(QT_NO_SSL)
const QString pkcs12File = parser.value(options.pkcs12File), pkcs12Password = parser.value(options.pkcs12Password);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split on two separate lines for readability.

@jtjbrady jtjbrady force-pushed the master branch 2 times, most recently from d25b49b to 65bac9c Compare June 20, 2025 10:03
@jtjbrady
Copy link
Contributor Author

Ok, so other than the different formatting for QCommandLineParser's help output, the "Usage" text is currently different.

The old text was:

Usage:
   Header file: bin\kdwsdl2cpp-qt6.exe [options] -o <headerfile> <wsdlfile>
   Impl.  file: bin\kdwsdl2cpp-qt6.exe [options] -o <cppfile> -impl <headerfile> <wsdlfile>
   Both files : bin\kdwsdl2cpp-qt6.exe [options] -both <basefile> <wsdlfile>

The new text is just:

Usage: bin\kdwsdl2cpp-qt6.exe [options] <wsdlfile>
KDAB's WSDL to C++ compiler

Are you happy with this, or do you want any changes?

@dfaure-kdab
Copy link
Member

Are you happy with this, or do you want any changes?

Good point, it makes the main modes of operations quite hidden compared to before.
But since the usage line is generated by QCLP, I guess the only way to improve that is to expand the string "KDAB's WSDL..." to mention the 3 modes of operations?

@jtjbrady
Copy link
Contributor Author

I guess the only way to improve that is to expand the string "KDAB's WSDL..." to mention the 3 modes of operations?

Correct.

I was thinking:

    parser.setApplicationDescription(QStringLiteral("%1\n\n"
                                                    "   Header file: %2 [options] -o <headerfile> <wsdlfile>\n"
                                                    "   Impl.  file: %2 [options] -o <cppfile> -impl <headerfile> <wsdlfile>\n"
                                                    "   Both files : %2 [options] -both <basefile> <wsdlfile>")
                                         .arg(WSDL2CPP_DESCRIPTION, QCoreApplication::applicationFilePath()));

Which results in:

Usage: bin\kdwsdl2cpp-qt6.exe [options] <wsdlfile>
KDAB's WSDL to C++ compiler

   Header file: bin/kdwsdl2cpp-qt6.exe [options] -o <headerfile> <wsdlfile>
   Impl.  file: bin/kdwsdl2cpp-qt6.exe [options] -o <cppfile> -impl <headerfile> <wsdlfile>
   Both files : bin/kdwsdl2cpp-qt6.exe [options] -both <basefile> <wsdlfile>

Options:
  -?, -h, --help                     Displays help on commandline options.
  --help-all                         Displays help, including generic Qt
                                     options.

I was also wondering what the "generic Qt options" were. The only one that gets added with --help-all is --qmljsdebugger. Any idea why a qml option is getting added for a non gui app?

@dfaure-kdab
Copy link
Member

Hmm, because the code for it is in QCoreApplicationPrivate...

 214│ #if QT_CONFIG(commandlineparser)
 215│ void QCoreApplicationPrivate::addQtOptions(QList<QCommandLineOption> *options)
 216├>{
 217│     options->append(QCommandLineOption(QStringLiteral("qmljsdebugger"),
 218│                 QStringLiteral("Activates the QML/JS debugger with a specified port. The value must be of format port:1234[,block]. \"block\" makes the application wait for a connection."),
 219│                 QStringLiteral("value")));
 220│ }
 221│ #endif

@dfaure-kdab
Copy link
Member

I did that in https://codereview.qt-project.org/c/qt/qtbase/+/261733 because the code that handles that option is actually in QCoreApplication (and that's documented in the QCoreApplication class documentation: \note QCoreApplication removes option \c -qmljsdebugger="...". It parses the argument of \c qmljsdebugger, and then removes this option plus its argument.)

I see. The parsing is in QCoreApplication, and then it's used by qtdeclarative/src/qml/debugger/qqmldebugconnector.cpp which is a core-only library. Really just the QML engine, nothing related to UI.

@jtjbrady
Copy link
Contributor Author

Ok I didn't realise it was possible to use Qml in a console application, but I suppose that is what qbs is/was?

@dfaure-kdab
Copy link
Member

Right, good example.

@dfaure-kdab dfaure-kdab merged commit 301aa34 into KDAB:master Jun 20, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants