QIntValidator Class

QIntValidator 클래스는 문자열이 지정된 범위 내에서 유효한 정수를 포함하는지 확인하는 유효성 검사기를 제공합니다. 더 보기...

Header: #include <QIntValidator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
상속합니다: QValidator

속성

공용 함수

QIntValidator(QObject *parent = nullptr)
QIntValidator(int minimum, int maximum, QObject *parent = nullptr)
virtual ~QIntValidator()
int bottom() const
void setBottom(int)
void setRange(int bottom, int top)
void setTop(int)
int top() const

재구현된 공용 함수

virtual void fixup(QString &input) const override
virtual QValidator::State validate(QString &input, int &pos) const override

신호

void bottomChanged(int bottom)
void topChanged(int top)

상세 설명

사용 예시:

QValidator *validator = new QIntValidator(100, 999, this);
QLineEdit *edit = new QLineEdit(this);

// the edit lineedit will only accept integers between 100 and 999
edit->setValidator(validator);

아래에는 유효성 검사기의 몇 가지 예가 나와 있습니다. 실제로는 위 예시처럼 위젯과 연결되는 것이 일반적입니다.

QString str;
int pos = 0;
QIntValidator v(100, 900, this);

str = "1";
v.validate(str, pos);     // returns Intermediate
str = "012";
v.validate(str, pos);     // returns Intermediate

str = "123";
v.validate(str, pos);     // returns Acceptable
str = "678";
v.validate(str, pos);     // returns Acceptable

str = "999";
v.validate(str, pos);    // returns Intermediate

str = "1234";
v.validate(str, pos);     // returns Invalid
str = "-123";
v.validate(str, pos);     // returns Invalid
str = "abc";
v.validate(str, pos);     // returns Invalid
str = "12cm";
v.validate(str, pos);     // returns Invalid

999 값은 Intermediate를 반환합니다. 최대값보다 작거나 같은 숫자로 구성된 값은 중간값으로 간주됩니다. 이는 숫자가 범위에 포함되지 않는 숫자가 반드시 입력한 마지막 숫자가 아닐 수 있기 때문입니다. 이는 또한 중간 숫자에 선행 0이 포함될 수 있음을 의미합니다.

최소값과 최대값은 setRange()로 한 번에 설정하거나 setBottom() 및 setTop()로 개별적으로 설정할 수 있습니다.

QIntValidator는 locale()를 사용하여 숫자를 해석합니다. 예를 들어 아랍어 로케일에서 QIntValidator는 아랍어 숫자를 허용합니다.

참고: locale()에 설정된 QLocale::NumberOptions 도 숫자가 해석되는 방식에 영향을 줍니다. 예를 들어 QLocale::RejectGroupSeparator 는 기본적으로 설정되어 있지 않으므로 유효성 검사기는 그룹 구분 기호를 허용합니다. 따라서 QLocale::toInt()를 사용하여 숫자 값을 가져오는 것이 좋습니다.

QDoubleValidator, QRegularExpressionValidator, QLocale::toInt() 및 줄 편집 예시도참조하세요 .

속성 문서

bottom : int

이 속성은 유효성 검사기의 허용 가능한 최저값을 보유합니다.

기본적으로 이 프로퍼티의 값은 사용 가능한 가장 낮은 부호 있는 정수(-2147483648)에서 파생됩니다.

액세스 함수:

int bottom() const
void setBottom(int)

알림 신호:

void bottomChanged(int bottom)

setRange()도 참조하세요 .

top : int

이 속성은 유효성 검사기의 허용 가능한 최고 값을 보유합니다.

기본적으로 이 속성의 값은 사용 가능한 가장 높은 부호 있는 정수에서 파생됩니다(2147483647).

액세스 함수:

int top() const
void setTop(int)

알림 신호:

void topChanged(int top)

setRange()도 참조하세요 .

멤버 함수 문서

[explicit] QIntValidator::QIntValidator(QObject *parent = nullptr)

모든 정수를 허용하는 parent 객체로 유효성 검사기를 구축합니다.

QIntValidator::QIntValidator(int minimum, int maximum, QObject *parent = nullptr)

minimum 에서 maximum 까지의 정수를 허용하는 parent 를 사용하여 유효성 검사기를 구축합니다.

[virtual noexcept] QIntValidator::~QIntValidator()

유효성 검사기를 삭제합니다.

[override virtual] void QIntValidator::fixup(QString &input) const

재구현합니다: QValidator::fixup(QString &input) const.

void QIntValidator::setRange(int bottom, int top)

bottom ~ top 사이의 정수만 허용하도록 유효성 검사기 범위를 설정합니다.

[override virtual] QValidator::State QIntValidator::validate(QString &input, int &pos) const

재구현합니다: QValidator::validate(QString &input, int &pos) const.

input 가 유효한 범위 내의 정수이면 Acceptable 를 반환합니다. input 의 자릿수가 범위의 최상위까지이거나 유효한 범위의 정수의 접두사이면 Intermediate 을 반환합니다. 그렇지 않으면 Invalid 을 반환합니다.

유효한 범위가 양의 정수(예: 32~100)로만 구성되어 있고 input 이 음수인 경우 Invalid가 반환됩니다. (반면에 범위가 음의 정수(예: -100 ~ -32)로 구성되어 있고 input 이 선행 더하기 기호가 없는 양의 정수인 경우 사용자가 마이너스를 입력하려고 할 수 있으므로 Intermediate가 반환됩니다(특히 오른쪽에서 왼쪽으로 쓰는 언어의 경우).

마찬가지로 유효한 범위가 46에서 53 사이인 경우 41에서 59는 Intermediate 로 평가되며, 그렇지 않으면 사용자가 49에서 51로 값을 변경할 수 없기 때문입니다.

int pos = 0;

s = "abc";
v.validate(s, pos);    // returns Invalid

s = "5";
v.validate(s, pos);    // returns Intermediate

s = "50";
v.validate(s, pos);    // returns Acceptable

기본적으로 pos 매개 변수는 이 유효성 검사기에서 사용되지 않습니다.

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