QCollatorSortKey Class | Qt Core | Qt 6.11.0
Description: The QCollatorSortKey class can be used to speed up string collation.

- Qt 6.11
- Qt Core
- C++ Classes
- QCollatorSortKey
- Qt 6.11.0 Reference Documentation

# QCollatorSortKey Class

The QCollatorSortKey class can be used to speed up string collation. More...

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

- List of all members, including inherited members
- QCollatorSortKey is part of Classes for string data and Implicitly Shared Classes.

Note: All functions in this class are reentrant.

## Public Functions

| QCollatorSortKey(const QCollatorSortKey &other)
`(since 6.8)` | QCollatorSortKey(QCollatorSortKey &&other)
| ~QCollatorSortKey()
int | compare(const QCollatorSortKey &otherKey) const
void | swap(QCollatorSortKey &other)
QCollatorSortKey & | operator=(QCollatorSortKey &&other)
QCollatorSortKey & | operator=(const QCollatorSortKey &other)

## Related Non-Members

bool | operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs)

## Detailed Description

The QCollatorSortKey class is always created by QCollator::sortKey() and is used for fast strings collation, for example when collating many strings.

See also QCollator, QCollator::sortKey(), and compare().

## Member Function Documentation

### QCollatorSortKey::QCollatorSortKey(const QCollatorSortKey &other)

Constructs a copy of the other collator key.

### `[constexpr noexcept, since 6.8]` QCollatorSortKey::QCollatorSortKey(QCollatorSortKey &&other)

Move-constructs a new QCollatorSortKey from other.

Note: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

This function was introduced in Qt 6.8.

### `[noexcept]` QCollatorSortKey::~QCollatorSortKey()

Destroys the collator key.

### int QCollatorSortKey::compare(const QCollatorSortKey &otherKey) const

Compares this key to otherKey, which must have been created by the same QCollator's sortKey() as this key. The comparison is performed in accordance with that QCollator's sort order.

Returns a negative value if this key sorts before otherKey, 0 if the two keys are equal or a positive value if this key sorts after otherKey.

See also operator<().

### `[noexcept]` void QCollatorSortKey::swap(QCollatorSortKey &other)

Swaps this collator key with other. This operation is very fast and never fails.

### `[noexcept]` QCollatorSortKey &QCollatorSortKey::operator=(QCollatorSortKey &&other)

Move-assigns other to this QCollatorSortKey instance.

Note: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

### QCollatorSortKey &QCollatorSortKey::operator=(const QCollatorSortKey &other)

Assigns other to this collator key.

## Related Non-Members

### bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs)

Both keys must have been created by the same QCollator's sortKey(). Returns `true` if lhs should be sorted before rhs, according to the QCollator that created them; otherwise returns `false`.

See also QCollatorSortKey::compare().