QCollator Class
QCollator 클래스는 지역화된 정렬 알고리즘에 따라 문자열을 비교합니다. 더 보기...
| 헤더: | #include <QCollator> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
- 상속된 멤버를 포함한 모든 멤버 목록
- QCollator는 문자열 데이터용 클래스와 암시적 공유 클래스의 일부입니다.
참고: 이 클래스의 모든 함수는 재진입 가능합니다.
QCollator 비교
| 범주 | 비교 가능한 유형 |
|---|---|
| 동등성 | QCollator |
공개 함수
| QCollator() | |
| QCollator(const QLocale &locale) | |
| QCollator(const QCollator &other) | |
| QCollator(QCollator &&other) | |
| ~QCollator() | |
| Qt::CaseSensitivity | caseSensitivity() const |
| int | compare(QStringView s1, QStringView s2) const |
| int | compare(const QString &s1, const QString &s2) const |
| int | compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const |
| bool | ignorePunctuation() const |
| QLocale | locale() const |
| bool | numericMode() const |
| void | setCaseSensitivity(Qt::CaseSensitivity cs) |
| void | setIgnorePunctuation(bool on) |
| void | setLocale(const QLocale &locale) |
| void | setNumericMode(bool on) |
| QCollatorSortKey | sortKey(const QString &string) const |
| void | swap(QCollator &other) |
| bool | operator()(QStringView s1, QStringView s2) const |
| bool | operator()(const QString &s1, const QString &s2) const |
| QCollator & | operator=(QCollator &&other) |
| QCollator & | operator=(const QCollator &other) |
정적 공용 멤버
(since 6.3) int | defaultCompare(QStringView s1, QStringView s2) |
(since 6.3) QCollatorSortKey | defaultSortKey(QStringView key) |
관련 비회원
(since 6.12) bool | operator!=(const QCollator &lhs, const QCollator &rhs) |
(since 6.12) bool | operator==(const QCollator &lhs, const QCollator &rhs) |
상세 설명
QCollator는 로케일( QLocale)을 사용하여 초기화됩니다. 이후 해당 로케일에 적합한 정렬 순서를 사용하여 문자열을 비교하고 정렬하는 데 사용할 수 있습니다.
QCollator 객체는 std::sort()와 같은 템플릿 기반 정렬 알고리즘과 함께 사용하여 로케일 QString 항목이 포함된 목록을 정렬할 수 있습니다.
QStringList sortedStrings(QStringList seq)
{
QCollator order;
std::sort(seq.begin(), seq.end(), order);
return seq;
}로케일 외에도, 정렬 결과에 영향을 미치는 몇 가지 선택적 플래그를 설정할 수 있습니다.
POSIX 대체 구현
유닉스 시스템에서 Qt는 일반적으로 ICU를 사용하도록 컴파일됩니다(macOS는 예외이며, 이 경우 Qt는 기본적으로 동등한 Apple API를 사용합니다). 그러나 컴파일 시점에 ICU를 사용할 수 없거나 명시적으로 비활성화된 경우, Qt는 POSIX API만을 사용하는 대체 백엔드를 사용합니다. 이 백엔드에는 다음과 같은 몇 가지 제한 사항이 있습니다:
- QLocale::c() 및 QLocale::system() 로케일만 지원됩니다. 시스템 로케일에 대한 자세한 내용은 POSIX 및 C 표준 라이브러리 매뉴얼의 `
<locale.h>` 헤더를 참조하십시오. - caseSensitivity()는 지원되지 않습니다. 대소문자를 구분하는 정렬만 수행할 수 있습니다.
- numericMode() 및 ignorePunctuation()은 지원되지 않습니다.
지원되지 않는 옵션을 사용하면 애플리케이션 출력에 경고가 표시됩니다.
멤버 함수 설명서
QCollator::QCollator()
기본 로캘의 정렬 로캘을 사용하여 QCollator 객체를 생성합니다.
시스템 로케일을 기본 로케일로 사용할 경우, 해당 로케일 자체와는 다른 정렬 로케일을 가질 수 있습니다(예: Unix에서 환경 변수 LC_COLLATE가 LANG과 다르게 설정된 경우). 그 외의 모든 로케일은 자체 정렬 로케일을 사용합니다.
setLocale(), QLocale::collation(), QLocale::setDefault()도 참조하십시오 .
[explicit] QCollator::QCollator(const QLocale &locale)
주어진 ` locale`를 사용하여 `QCollator`를 생성합니다.
setLocale()도 참조하십시오 .
QCollator::QCollator(const QCollator &other)
other 의 복사본을 생성합니다.
[noexcept] QCollator::QCollator(QCollator &&other)
이동 생성자. other 에서 이 콜레이터로 값을 이동합니다.
참고: 이동된대상 객체인 other 는 부분적으로 형성된 상태가 되며, 이 상태에서는 소멸과 새 값 할당만이 유효한 연산입니다.
[noexcept] QCollator::~QCollator()
이 정렬기를 삭제합니다.
Qt::CaseSensitivity QCollator::caseSensitivity() const
콜레이터의 대소문자 구분 여부를 반환합니다.
이 속성이 설정되기 전까지는 대소문자를 구분하는 것이 기본값입니다.
참고: C로케일에서 대소문자를 구분하는 경우, 모든 소문자는 모든 대문자보다 뒤에 정렬됩니다. 반면 대부분의 로케일에서는 각 소문자가 해당 대문자 바로 앞이나 바로 뒤에 정렬됩니다. 따라서 C 로케일에서는 "Zap"이 "ape"보다 앞에 정렬되지만, 대부분의 다른 로케일에서는 그 반대입니다.
setCaseSensitivity()도 참조하십시오 .
int QCollator::compare(QStringView s1, QStringView s2) const
s1 와 s2 를 비교합니다.
s1 가 s2 보다 작으면 음의 정수를, s2 보다 크면 양의 정수를, 둘이 같으면 0을 반환합니다.
int QCollator::compare(const QString &s1, const QString &s2) const
이것은 오버로드된 함수입니다.
int QCollator::compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const
s1 와 s2 를 비교합니다. len1 와 len2 는 s1 와 s2 가 가리키는 QChar 배열의 길이를 지정합니다.
s1 가 s2 보다 작으면 음의 정수를, s2 보다 크면 양의 정수를, 둘이 같으면 0을 반환합니다.
참고: Qt 6.4 이전버전에서는 길이 인자의 형식이 qsizetype 이 아닌 int 이었습니다.
이 함수는 오버로드된 함수입니다.
[static, since 6.3] int QCollator::defaultCompare(QStringView s1, QStringView s2)
s1 와 s2 라는 두 문자열을 비교하여 두 문자열의 정렬 순서를 반환합니다. 이 함수는 기본 생성된 QCollator 객체에 대해 compare()과 동일한 작업을 수행합니다.
이 함수는 Qt 6.3에서 도입되었습니다.
compare() 및 defaultSortKey()도 참조하십시오 .
[static, since 6.3] QCollatorSortKey QCollator::defaultSortKey(QStringView key)
key 라는 문자열에 대한 정렬 키를 반환합니다. 이 함수는 기본 생성된 QCollator 객체에 대해 sortKey()과 동일한 작업을 수행합니다.
이 함수는 Qt 6.3에서 도입되었습니다.
sortKey() 및 defaultCompare()도 참조하십시오 .
bool QCollator::ignorePunctuation() const
정렬 시 구두점과 기호가 무시되는지 여부를 반환합니다.
true 인 경우, 각 문자열에서 모든 구두점과 기호가 제거된 것처럼 문자열이 비교됩니다.
setIgnorePunctuation()도 참조하십시오 .
QLocale QCollator::locale() const
콜레이터의 로케일을 반환합니다.
생성자에 전달되거나 ` setLocale()`를 호출하여 지정되지 않는 한, 시스템의 기본 정렬 로캘이 사용됩니다.
setLocale() 및 QLocale::collation()도 참조하십시오 .
bool QCollator::numericMode() const
숫자 정렬이 활성화되어 있으면 ` true `을 반환하고, 그렇지 않으면 ` false `을 반환합니다.
true 인 경우, 숫자는 숫자로 인식되어 산술 순서대로 정렬됩니다. 예를 들어, 100은 99보다 뒤에 옵니다. false 인 경우, 숫자는 어순대로 정렬되므로 100은 99보다 앞에 옵니다(1이 9보다 먼저 오기 때문입니다). 기본적으로 이 옵션은 비활성화되어 있습니다.
setNumericMode()도 참조하십시오 .
void QCollator::setCaseSensitivity(Qt::CaseSensitivity cs)
콜레이터의 대소문자 구분 설정을 ‘ cs ’로 설정합니다.
caseSensitivity()도 참조하십시오 .
void QCollator::setIgnorePunctuation(bool on)
on 가 true 인 경우 구두점과 기호를 무시하고, false 인 경우 이를 고려합니다.
ignorePunctuation()도 참조하십시오 .
void QCollator::setLocale(const QLocale &locale)
콜레이터의 로케일을 locale 로 설정합니다.
locale()도 참조하십시오 .
void QCollator::setNumericMode(bool on)
on 의 값이 true 일 때 숫자 정렬 모드를 활성화합니다.
numericMode()도 참조하십시오 .
QCollatorSortKey QCollator::sortKey(const QString &string) const
string 에 사용할 sortKey를 반환합니다.
정렬 키를 생성하는 것은 일반적으로 ` compare()` 메서드를 직접 사용하는 것보다 다소 느립니다. 하지만 문자열을 반복적으로 비교해야 하는 경우(예: 전체 문자열 목록을 정렬할 때), 각 문자열에 대한 정렬 키를 생성한 다음 해당 키를 사용하여 정렬하는 것이 대개 더 빠릅니다.
참고: Darwin의 C(일명 POSIX) 로케일에서는 지원되지않습니다 .
[noexcept] void QCollator::swap(QCollator &other)
이 콜레이터를 other 로 교체합니다. 이 작업은 매우 빠르며 절대 실패하지 않습니다.
bool QCollator::operator()(QStringView s1, QStringView s2) const
QCollator 는 정렬 알고리즘의 비교 함수로 사용할 수 있습니다. 이 함수는 s1 가 s2 보다 먼저 정렬될 경우 true 를 반환하고, 그렇지 않은 경우 false 를 반환합니다.
compare()도 참조하십시오 .
bool QCollator::operator()(const QString &s1, const QString &s2) const
이것은 오버로드된 함수입니다.
[noexcept] QCollator &QCollator::operator=(QCollator &&other)
other 를 이 QCollator 인스턴스에 이동 할당합니다.
참고: 이동된객체 other 는 부분적으로 형성된 상태가 되며, 이 상태에서는 소멸과 새 값 할당만이 유효한 연산입니다.
QCollator &QCollator::operator=(const QCollator &other)
이 정렬기에 ‘ other ’를 할당합니다.
© 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.