- Qt 6.7
- Qt SQL
- C++ Classes
- QSqlIndex
- Qt 6.7.3 Reference Documentation

# QSqlIndex Class

The QSqlIndex class provides functions to manipulate and describe database indexes. More...

Header: | #include <QSqlIndex>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Sql) target_link_libraries(mytarget PRIVATE Qt6::Sql)
qmake: | QT += sql
Inherits: | QSqlRecord

- List of all members, including inherited members
- QSqlIndex is part of Database Classes.

## Public Functions

| QSqlIndex(const QString &cursorname = QString(), const QString &name = QString())
| QSqlIndex(const QSqlIndex &other)
`(since 6.6)` | QSqlIndex(QSqlIndex &&other)
| ~QSqlIndex()
void | append(const QSqlField &field)
void | append(const QSqlField &field, bool desc)
QString | cursorName() const
bool | isDescending(int i) const
QString | name() const
void | setCursorName(const QString &cursorName)
void | setDescending(int i, bool desc)
void | setName(const QString &name)
QSqlIndex & | operator=(const QSqlIndex &other)
`(since 6.6)` QSqlIndex & | operator=(QSqlIndex &&other)

## Detailed Description

An index refers to a single table or view in a database. Information about the fields that comprise the index can be used to generate SQL statements.

## Member Function Documentation

### `[explicit]` QSqlIndex::QSqlIndex(const QString &cursorname = QString(), const QString &name = QString())

Constructs an empty index using the cursor name cursorname and index name name.

### QSqlIndex::QSqlIndex(const QSqlIndex &other)

Constructs a copy of other.

### `[noexcept, since 6.6]` QSqlIndex::QSqlIndex(QSqlIndex &&other)

Move-constructs a new QSqlIndex 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.6.

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

Destroys the object and frees any allocated resources.

### void QSqlIndex::append(const QSqlField &field)

Appends the field field to the list of indexed fields. The field is appended with an ascending sort order.

### void QSqlIndex::append(const QSqlField &field, bool desc)

This is an overloaded function.

Appends the field field to the list of indexed fields. The field is appended with an ascending sort order, unless desc is true.

### QString QSqlIndex::cursorName() const

Returns the name of the cursor which the index is associated with.

See also setCursorName().

### bool QSqlIndex::isDescending(int i) const

Returns `true` if field i in the index is sorted in descending order; otherwise returns `false`.

### QString QSqlIndex::name() const

Returns the name of the index.

See also setName().

### void QSqlIndex::setCursorName(const QString &cursorName)

Sets the name of the cursor that the index is associated with to cursorName.

See also cursorName().

### void QSqlIndex::setDescending(int i, bool desc)

If desc is true, field i is sorted in descending order. Otherwise, field i is sorted in ascending order (the default). If the field does not exist, nothing happens.

See also isDescending().

### void QSqlIndex::setName(const QString &name)

Sets the name of the index to name.

See also name().

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

Sets the index equal to other.

### `[noexcept, since 6.6]` QSqlIndex &QSqlIndex::operator=(QSqlIndex &&other)

Move-assigns other to this QSqlIndex 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.

This function was introduced in Qt 6.6.