|  | Home · All Classes · Main Classes · Annotated · Grouped Classes · Functions |

# QModelIndex Class Reference

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

    #include <QModelIndex>

Part of the QtCore module.

- List of all members, including inherited members

### Public Functions

- QModelIndex ()
- QModelIndex ( const QModelIndex & other )
- ~QModelIndex ()
- QModelIndex child ( int row, int column ) const
- int column () const
- bool isValid () const
- const QAbstractItemModel * model () const
- QModelIndex parent () const
- int row () const
- QModelIndex sibling ( int row, int column ) const
- bool operator!= ( const QModelIndex & other ) const
- bool operator== ( const QModelIndex & other ) const

## Detailed Description

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

This class is used as an index into item models derived from QAbstractItemModel. The index is used by item views, delegates, and selection models to locate an item in the model. QModelIndex objects are created by the model.

Model indexes contain all the information required to specify the items they refer to in a model. Indexes are located in a row and a column, and they may have a parent index; use row(), column(), and parent() to obtain this information. Top-level items in a model are represented by model indexes that do not have a parent index - in this case, parent() will return an invalid model index that is equivalent to an index constructed with the zero argument form of the QModelIndex() constructor.

To obtain a model index that refers to an item in a model, call index() with the required row and column values, and the parent model index. Supply the zero argument form of the QModelIndex() constructor as the parent index when referring to top-level items in a model.

The model() function returns the model that the index references as a QAbstractItemModel. The child() function is used to examine the items held beneath the index in the model. The sibling() function allows you to traverse items in the model on the same level as the index.

Model indexes can become invalid over time so they should be used immediately and then discarded. If you need to keep a model index over time use a QPersistentModelIndex.

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

## Member Function Documentation

### QModelIndex::QModelIndex ()

Creates a new empty model index. This type of model index is used to indicate that the position in the model is invalid.

See also isValid() and QAbstractItemModel.

### QModelIndex::QModelIndex ( const QModelIndex & other )

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

### QModelIndex::~QModelIndex ()

Destroys the model index.

### QModelIndex QModelIndex::child ( int row, int column ) const

Returns the child of the model index that is stored in the given row and column.

See also parent() and sibling().

### int QModelIndex::column () const

Returns the column this model index refers to.

### bool QModelIndex::isValid () const

Returns true if this model index is valid; otherwise returns false.

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

Returns a pointer to the model containing the item that this index refers to.

### QModelIndex QModelIndex::parent () const

Return the parent of the model index, or QModelIndex() if it has no parent.

See also child(), sibling(), and model().

### int QModelIndex::row () const

Returns the row this model index refers to.

### QModelIndex QModelIndex::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() and child().

### bool QModelIndex::operator!= ( const QModelIndex & other ) const

Returns true if this model index does not refer to the same location as the other model index; otherwise returns false.

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

Returns true if this model index refers to the same location as the other model index; otherwise returns false.