6.0.0-rc4Source

QModelIndex Class

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

Header#include <QModelIndex>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QModelIndex()
introw() const
intcolumn() const
quintptrinternalId() const
void *internalPointer() const
const void *constInternalPointer() const
QModelIndexparent() const
QModelIndexsibling(int row, int column) const
QModelIndexsiblingAtColumn(int column) const
QModelIndexsiblingAtRow(int row) const
QVariantdata(int role = Qt::DisplayRole) const
Qt::ItemFlagsflags() const
const QAbstractItemModel *model() const
boolisValid() const

Detailed Description

A model index refers to an item of a QAbstractItemModel by its row, its column and its parent. Models create indexes with QAbstractItemModel::createIndex(); views and delegates use them to read and change data. An index is only valid until the model's structure changes; use QPersistentModelIndex to keep one.

const QModelIndex index = model->index(2, 0);
const QString text = index.data().toString();

See also QAbstractItemModel and QPersistentModelIndex.

Differences from Qt

There is no multiData() and no QModelRoleDataSpan.

Member Function Documentation

[constexpr] QModelIndex::QModelIndex()

Constructs an invalid index, which refers to the root of a model.

[constexpr] int QModelIndex::column() const

Returns the column of the index, or -1 if it is invalid.

const void * QModelIndex::constInternalPointer() const

Returns the pointer the model stored in the index, as a pointer to const.

This function was introduced in 6.0.

QVariant QModelIndex::data(int role = Qt::DisplayRole) const

Returns the data of the item for role, or an invalid QVariant.

Qt::ItemFlags QModelIndex::flags() const

Returns the flags of the item.

[constexpr] quintptr QModelIndex::internalId() const

Returns the integer the model stored in the index.

See also internalPointer().

void * QModelIndex::internalPointer() const

Returns the pointer the model stored in the index.

See also internalId().

[constexpr] bool QModelIndex::isValid() const

Returns true if the index refers to an item; otherwise returns false.

[constexpr] const QAbstractItemModel * QModelIndex::model() const

Returns the model that the index belongs to, or nullptr for an invalid index.

QModelIndex QModelIndex::parent() const

Returns the parent of the item, or an invalid index for a top-level item or an invalid index.

[constexpr] int QModelIndex::row() const

Returns the row of the index, or -1 if it is invalid.

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

Returns the index at row and column under the same parent, or an invalid index.

QModelIndex QModelIndex::siblingAtColumn(int column) const

Returns the index in column of the same row.

This function was introduced in 5.11.

QModelIndex QModelIndex::siblingAtRow(int row) const

Returns the index in row of the same column.

This function was introduced in 5.11.