이 페이지에서

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, IgnoreOptionsAfter }
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`에 의해 설정된 값과 관계없이 항상 짧은 옵션으로 인식됩니다. 이를 통해 파서가 ` QCommandLineParser::ParseAsLongOptions ` 모드에 있을 때에도 ` -DDEFINE=VALUE `이나 ` -I/include/path `과 같은 플래그가 짧은 플래그로 해석될 수 있습니다.
QCommandLineOption::IgnoreOptionsAfter0x4[6.9부터] 이 옵션 이후의 옵션은 파싱되지 않습니다. 보조 애플리케이션에 추가 명령줄 인수를 전달해야 하는 경우에 유용합니다. 이 옵션에 값이 지정된 경우, 해당 값은 무시됩니다.

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 라는 이름의 명령줄 옵션 객체를 생성합니다.

이 오버로드를 사용하면 옵션에 여러 이름을 설정할 수 있습니다. 예를 들어, o 및 output 과 같이 설정할 수 있습니다.

이름은 짧은 이름이나 긴 이름일 수 있습니다. 목록에 있는 이름 중 길이가 1자인 이름은 짧은 이름입니다. 옵션 이름은 비어 있어서는 안 되며, 대시나 슬래시 문자로 시작해서는 안 되고, = 를 포함해서는 안 되며, 중복되어서는 안 됩니다.

setDescription(), setValueName() 및 setDefaultValues()도 참조하십시오 .

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

지정된 인수를 사용하여 명령줄 옵션 객체를 생성합니다.

옵션 이름은 name 로 설정됩니다. 이름은 짧은 이름이나 긴 이름일 수 있습니다. 이름의 길이가 한 글자인 경우 짧은 이름으로 간주됩니다. 옵션 이름은 비어 있어서는 안 되며, 대시나 슬래시 문자로 시작해서는 안 되고, = 을 포함해서는 안 되며, 중복되어서는 안 됩니다.

설명(description)은 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())

지정된 인수를 사용하여 명령줄 옵션 객체를 생성합니다.

이 오버로드를 사용하면 옵션에 여러 개의 이름을 지정할 수 있습니다. 예를 들어, o 및 output 와 같이 지정할 수 있습니다.

옵션 이름은 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)

other 의 QCommandLineOption 객체를 복사한 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 로 설정합니다.

값이 할당되지 않은 옵션은 부울(boolean)과 유사한 동작을 보입니다. 즉, 사용자가 –option을 명시적으로 지정하거나 그렇지 않은 경우입니다.

값이 할당된 옵션의 경우, 도움말 출력에 표시될 옵션 설명에 사용될 예상 값의 이름을 설정해야 합니다. 이름이 o 및 output 이고 값 이름이 file 인 옵션은 -o, --output <file> 로 표시됩니다.

해당 옵션이 한 번만 존재할 것으로 예상되는 경우 ` QCommandLineParser::value()`를 호출하고, 여러 번 존재할 것으로 예상되는 경우 ` QCommandLineParser::values()`를 호출하십시오.

valueName()도 참조하십시오 .

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

이 옵션을 ` other`로 바꿉니다. 이 작업은 매우 빠르며 절대 실패하지 않습니다.

QString QCommandLineOption::valueName() const

예상되는 값의 이름을 반환합니다.

빈 값인 경우, 해당 옵션은 값을 받지 않습니다.

setValueName()도 참조하십시오 .

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

other 를 이 QCommandLineOption 인스턴스에 할당합니다.

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

other 객체의 복사본을 생성하여 이 QCommandLineOption 객체에 할당합니다.

© 2026 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.