- Qt 6.9
- Qt Core
- C++ Classes
- QPersistentModelIndex
- Qt 6.9.2 Reference Documentation

# QPersistentModelIndex Class

The QPersistentModelIndex class is used to locate data in a data model. More...

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

- List of all members, including inherited members
- QPersistentModelIndex is part of Implicitly Shared Classes.

This class is strongly comparable.

This class is strongly comparable with QModelIndex.

## Public Functions

| QPersistentModelIndex(const QModelIndex &index)
QVariant | data(int role = Qt::DisplayRole) const
Qt::ItemFlags | flags() const
const QAbstractItemModel * | model() const
`(since 6.0)` void | multiData(QModelRoleDataSpan roleDataSpan) const
QModelIndex | parent() const
QModelIndex | sibling(int row, int column) const
QPersistentModelIndex & | operator=(const QModelIndex &other)
QPersistentModelIndex & | operator=(const QPersistentModelIndex &other)

## Related Non-Members

size_t | qHash(const QPersistentModelIndex &key, size_t seed = 0)

## Detailed Description

A QPersistentModelIndex is a model index that can be stored by an application, and later used to access information in a model. Unlike the QModelIndex class, it is safe to store a QPersistentModelIndex since the model will ensure that references to items will continue to be valid as long as they can be accessed by the model.

It is good practice to check that persistent model indexes are valid before using them.

Note: You cannot store a QStandardItemModel's QPersistentModelIndex in one of the model's items.

See also Model/View Programming, QModelIndex, and QAbstractItemModel.

## Member Function Documentation

### QPersistentModelIndex::QPersistentModelIndex(const QModelIndex &index)

Creates a new QPersistentModelIndex that is a copy of the model index.

### QVariant QPersistentModelIndex::data(int role = Qt::DisplayRole) const

Returns the data for the given role for the item referred to by the index, or a default-constructed QVariant if this persistent model index is invalid.

See also Qt::ItemDataRole and QAbstractItemModel::setData().

### Qt::ItemFlags QPersistentModelIndex::flags() const

Returns the flags for the item referred to by the index.

### const QAbstractItemModel *QPersistentModelIndex::model() const

Returns the model that the index belongs to.

### `[since 6.0]` void QPersistentModelIndex::multiData(QModelRoleDataSpan roleDataSpan) const

Populates the given roleDataSpan for the item referred to by the index.

This function was introduced in Qt 6.0.

See also Qt::ItemDataRole and QAbstractItemModel::setData().

### QModelIndex QPersistentModelIndex::parent() const

Returns the parent QModelIndex for this persistent index, or an invalid QModelIndex if it has no parent.

See also sibling() and model().

### QModelIndex QPersistentModelIndex::sibling(int row, int column) const

Returns the sibling at row and column or an invalid QModelIndex if there is no sibling at this position.

See also parent().

### QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other)

Sets the persistent model index to refer to the same item in a model as the other model index.

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

Sets the persistent model index to refer to the same item in a model as the other persistent model index.

## Related Non-Members

### `[noexcept]` size_t qHash(const QPersistentModelIndex &key, size_t seed = 0)

Returns the hash value for key, using seed to seed the calculation.