QCollator Class

QCollator 클래스는 지역화된 데이터 정렬 알고리즘에 따라 문자열을 비교합니다. 더 보기...

Header: #include <QCollator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

참고: 이 클래스의 모든 함수는 재진입됩니다.

공용 함수

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)

상세 설명

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() 로케일만 지원됩니다. 시스템 로캘에 대한 자세한 내용은 <locale.h> 헤더에 대한 POSIX 및 C 표준 라이브러리 매뉴얼을 참조하십시오.
  • 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 로캘에서 대소문자를 구분하는 경우 모든 소문자는 모든 대문자 다음에 정렬되지만, 대부분의 로캘은 각 소문자를 대문자 바로 앞 또는 바로 뒤에 정렬합니다. 따라서 "Zap"은 C 로캘에서는 "ape" 앞에 정렬되지만 대부분의 다른 로캘에서는 그 뒤에 정렬됩니다.

setCaseSensitivity()도 참조하세요 .

int QCollator::compare(QStringView s1, QStringView s2) const

s1s2 을 비교합니다.

s1s2 보다 작으면 음의 정수를, 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

이것은 오버로드된 함수입니다.

s1s2 을 비교합니다. len1len2s1s2 이 가리키는 QChar 배열의 길이를 지정합니다.

s1s2 보다 작으면 음의 정수를, s2 보다 크면 양의 정수를, 같으면 0을 반환합니다.

참고: 6.4 이전 Qt 버전에서, 길이 인자는 qsizetype 이 아닌 int 형이었습니다.

[static, since 6.3] int QCollator::defaultCompare(QStringView s1, QStringView s2)

s1s2 문자열을 비교하여 정렬 순서를 반환합니다. 이 함수는 기본으로 구성된 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)

ontrue 인 경우 구두점과 기호를 무시하고 false 인 경우 구두점과 기호를 사용합니다.

ignorePunctuation()도 참조하세요 .

void QCollator::setLocale(const QLocale &locale)

콜레이터의 로캘을 locale 로 설정합니다.

locale()도 참조하세요 .

void QCollator::setNumericMode(bool on)

ontrue 일 때 숫자 정렬 모드를 활성화합니다.

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 을 정렬 알고리즘의 비교 함수로 사용할 수 있습니다. s1s2 보다 먼저 정렬되면 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 을 할당합니다.

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