path: root/src/corelib/tools/qcommandlineoption.h
diff options
authorMarc Mutz <>2014-07-30 15:47:15 +0200
committerMarc Mutz <>2014-08-06 22:17:22 +0200
commit7f78d547ca843ad58b016b72418f5b9ab47c8148 (patch)
tree575f902ebf83a973521f55b4d2158a473c3abe6e /src/corelib/tools/qcommandlineoption.h
parenta2ad0ba630da3552b3c2d3d2f09db0a43e4fcc9d (diff)
QCommandLineParser: support extremely concise option configuration in C++11
The goal of this commit to make the code in the test work: QCommandLineParser parser; parser.addOptions({ { "a", "The A option." }, { { "v", "verbose" }, "The verbose option." }, { { "i", "infile" }, "The input file.", "value" }, }); For this, QCommandLineParser needs a version of addOption that can take a list of options. That's what addOptions() is for. More importantly, the QCommandLineOption ctors mustn't be explicit. OTOH, any implicit conversion from QString or QStringList to QCommandLineOption is also undesirable. To solve this dilemma, add new QCommandLineOption ctors that just take one argument and are explicit, and make the existing ctors implicit. In order to avoid ambiguities, remove the default values of their resp. 2nd arguments. The new ctors are by intention not \since 5.4, as they are completely transparent to the user. Et voila, even better than getopt_long(3). [ChangeLog][QtCore][QCommandLineParser] Added addOptions() method. Change-Id: I5e779f3406cd0f6c8ec6ecbf6c8074af226de300 Reviewed-by: Thiago Macieira <>
Diffstat (limited to 'src/corelib/tools/qcommandlineoption.h')
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/tools/qcommandlineoption.h b/src/corelib/tools/qcommandlineoption.h
index 49223cda37..0230586c29 100644
--- a/src/corelib/tools/qcommandlineoption.h
+++ b/src/corelib/tools/qcommandlineoption.h
@@ -52,10 +52,12 @@ class QCommandLineOptionPrivate;
class Q_CORE_EXPORT QCommandLineOption
- explicit QCommandLineOption(const QString &name, const QString &description = QString(),
+ explicit QCommandLineOption(const QString &name);
+ explicit QCommandLineOption(const QStringList &names);
+ /*implicit*/ QCommandLineOption(const QString &name, const QString &description,
const QString &valueName = QString(),
const QString &defaultValue = QString());
- explicit QCommandLineOption(const QStringList &names, const QString &description = QString(),
+ /*implicit*/ QCommandLineOption(const QStringList &names, const QString &description,
const QString &valueName = QString(),
const QString &defaultValue = QString());
QCommandLineOption(const QCommandLineOption &other);