QCommandLineOption Class

QCommandLineOption クラスは、可能なコマンドラインオプションを定義します。詳細...

ヘッダー #include <QCommandLineOption>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

パブリック型

enum Flag { HiddenFromHelp, ShortOptionStyle }
flags Flags

パブリック関数

QCommandLineOption(const QString &name)
QCommandLineOption(const QStringList &names)
QCommandLineOption(const QString &name, const QString &description, const QString &valueName = QString(), const QString &defaultValue = QString())
QCommandLineOption(const QStringList &names, const QString &description, const QString &valueName = QString(), const QString &defaultValue = QString())
QCommandLineOption(const QCommandLineOption &other)
~QCommandLineOption()
QStringList defaultValues() const
QString description() const
QCommandLineOption::Flags flags() const
QStringList names() const
void setDefaultValue(const QString &defaultValue)
void setDefaultValues(const QStringList &defaultValues)
void setDescription(const QString &description)
void setFlags(QCommandLineOption::Flags flags)
void setValueName(const QString &valueName)
void swap(QCommandLineOption &other)
QString valueName() const
QCommandLineOption &operator=(QCommandLineOption &&other)
QCommandLineOption &operator=(const QCommandLineOption &other)

詳細な説明

このクラスは、コマンドライン上のオプションを記述するために使用されます。複数のエイリアスが可能で、同じオプションをさまざまな方法で定義できます。また、オプションがどのように使われるかを記述するためにも使われます - フラグであったり (-v など)、値を取ったり (-o file など)。

例:

QCommandLineOption verboseOption("verbose", "Verbose mode. Prints out more information.");
QCommandLineOption outputOption(QStringList() << "o" << "output", "Write generated data into <file>.", "file");

QCommandLineParserも参照

メンバ型ドキュメント

enum QCommandLineOption::Flag
flags QCommandLineOption::Flags

定数説明
QCommandLineOption::HiddenFromHelp0x1ユーザが表示できるヘルプ出力で、このオプションを非表示にします。デフォルトでは、すべてのオプションが表示されます。特定のオプションにこのフラグを設定すると、そのオプションは内部オプションになり、ヘルプ出力には表示されなくなります。
QCommandLineOption::ShortOptionStyle0x2こ のオプシ ョ ンは、QCommandLineParser::setSingleDashWordOptionMode で設定 さ れてい る 内容にかかわ ら ず、 つねに短いオプシ ョ ン と し て理解 さ れます。こ れに よ り 、-DDEFINE=VALUE-I/include/path の よ う なフラグは、 パーザがQCommandLineParser::ParseAsLongOptions モー ド の と き で も 、 短いフラグ と し て解釈で き る よ う にな り ます。

Flags型はQFlags<Flag>のtypedefです。これはFlag値のORの組み合わせを格納します。

QCommandLineOption::setFlags() およびQCommandLineOption::flags()も参照

メンバ関数のドキュメント

[explicit] QCommandLineOption::QCommandLineOption(const QString &name)

name という名前のコマンドラインオプションオブジェクトを構築する。

名前には短いものと長いものがある。名前の長さが 1 文字の場合、短い名前とみなされます。オプション名は空であってはならず、ダッシュやスラッシュ文字で始まってはならず、= を含んではならず、繰り返してはならない。

setDescription ()、setValueName ()、setDefaultValues)も参照の こと。

[explicit] QCommandLineOption::QCommandLineOption(const QStringList &names)

names という名前のコマンドラインオプションオブジェクトを構築する。

このオーバーロードでは、オプションに複数の名前、たとえばooutput を設定することができます。

名前には、短いものと長いものがあります。リ ス ト 内の長 さ が 1 文字の名前はすべて、 短い名前です。オプション名は空であってはならず、ダッシュやスラッシュ文字で始まってはならず、= を含んでいてはならず、繰り返してはならない。

setDescription()、setValueName()、setDefaultValues()も参照の こと。

QCommandLineOption::QCommandLineOption(const QString &name, const QString &description, const QString &valueName = QString(), const QString &defaultValue = QString())

与えられた引数でコマンドラインオプションオブジェクトを構築する。

オプション名はname に設定される。名前の長さが1文字の場合、短い名前とみなされる。オプション名は空であってはならず、ダッシュやスラッシュ文字で始まってはならず、= を含んではならず、繰り返してはならない。

説明文はdescription に設定される。説明文の最後には". "を付けるのが通例である。

さらに、オプションが値を期待する場合はvalueName を設定する必要がある。オプションのデフォルト値はdefaultValue に設定されます。

Qt 5.4以前のバージョンでは、このコンストラクタはexplicit でした。 Qt 5.4以降では、このコンストラクタはなくなり、一様な初期化に使用できるようになりました:

QCommandLineParser parser;
parser.addOption({"verbose", "Verbose mode. Prints out more information."});

setDescription(),setValueName(),setDefaultValues()も参照してください

QCommandLineOption::QCommandLineOption(const QStringList &names, const QString &description, const QString &valueName = QString(), const QString &defaultValue = QString())

与えられた引数でコマンドラインオプションオブジェクトを構築する。

こ のオーバー ロ ー ド では、 オプシ ョ ンに複数の名前 (た と えばooutput ) を設定す る こ と がで き ます。

オプシ ョ ンの名前は、names に設定 さ れます。 名前には、 短い名前 も 長い名前 も あ り ます。リ ス ト の中で長 さ が 1 文字の名前はすべて、 短い名前です。オプシ ョ ン名は空であってはならず、ダッシュやスラッシュ文字で始まってはならず、= を含んではならず、繰り返してはならない。

説明文はdescription に設定される。説明文の最後には". "を付けるのが通例である。

さらに、オプションが値を期待する場合はvalueName を設定する必要がある。オプションのデフォルト値はdefaultValue に設定されます。

Qt 5.4以前のバージョンでは、このコンストラクタはexplicit でした。 Qt 5.4以降では、このコンストラクタはなくなり、一様な初期化に使用できるようになりました:

QCommandLineParser parser;
parser.addOption({{"o", "output"}, "Write generated data into <file>.", "file"});

setDescription(),setValueName(),setDefaultValues()も参照してください

QCommandLineOption::QCommandLineOption(const QCommandLineOption &other)

QCommandLineOption オブジェクトother のコピーである QCommandLineOption オブジェクトを構築します。

operator=()も参照してください

[noexcept] QCommandLineOption::~QCommandLineOption()

コマンドラインオプションオブジェクトを破棄します。

QStringList QCommandLineOption::defaultValues() const

このオプションに設定されているデフォルト値を返す。

setDefaultValues()も参照

QString QCommandLineOption::description() const

このオプションに設定されている説明を返す。

setDescription()も参照

QCommandLineOption::Flags QCommandLineOption::flags() const

このコマンドラインオプションに影響するフラグのセットを返す。

setFlags() およびQCommandLineOption::Flagsも参照のこと

QStringList QCommandLineOption::names() const

このオプションに設定されている名前を返します。

void QCommandLineOption::setDefaultValue(const QString &defaultValue)

このオプションに使用されるデフォルト値をdefaultValue に設定します。

このデフォルト値は、アプリケーションのユーザがコマンド行でオプションを指定しない場合に使用されます。

defaultValue が空の場合、このオプションにデフォルト値はありません。

defaultValues() およびsetDefaultValues()も参照

void QCommandLineOption::setDefaultValues(const QStringList &defaultValues)

このオプションに使用されるデフォルト値のリストをdefaultValues に設定します。

アプリケーションのユーザがコマンド行でオプションを指定しない場合、デフォルト値が使用される。

defaultValues() およびsetDefaultValue()も参照

void QCommandLineOption::setDescription(const QString &description)

このオプションに使われる説明をdescription に設定する。

説明の最後に". "を付けるのが通例である。

この説明はQCommandLineParser::showHelp() で使用される。

description()も参照

void QCommandLineOption::setFlags(QCommandLineOption::Flags flags)

このコマンドラインオプションに影響するフラグのセットをflags に設定する。

flags() およびQCommandLineOption::Flagsも参照のこと

void QCommandLineOption::setValueName(const QString &valueName)

ドキュメントに期待される値の名前をvalueName に設定します。

値が割り当てられていないオプションは、ブーリアンのような動作をします: ユーザーが -option を指定するか、指定しないかのどちらかです。

値を指定したオプションは、ヘルプ出力でオプションを説明するために、期待値の名前を設定する必要があります。名前がooutput で、値の名前がfile のオプションは、-o, --output <file> として表示されます。

そのオプションが1回だけ存在すると予想される場合はQCommandLineParser::value() を、そのオプションが複数回存在すると予想される場合はQCommandLineParser::values() を呼び出します。

valueName()も参照

[noexcept] void QCommandLineOption::swap(QCommandLineOption &other)

このオプションをother と入れ替える。この操作は非常に速く、失敗することはない。

QString QCommandLineOption::valueName() const

期待値の名前を返します。

空の場合、オプションは値を取りません。

setValueName()も参照してください

[noexcept] QCommandLineOption &QCommandLineOption::operator=(QCommandLineOption &&other)

Move-other をこのQCommandLineOption インスタンスに割り当てる。

QCommandLineOption &QCommandLineOption::operator=(const QCommandLineOption &other)

other オブジェクトのコピーを作成し、このQCommandLineOption オブジェクトに割り当てる。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.