Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QModelIndex Class Reference
[QtCore module]

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

 #include <QModelIndex>

Public Functions

Related Non-Members


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.

New QModelIndex objects are created by the model using the QAbstractItemModel::createIndex() function. An invalid model index can be constructed with the QModelIndex constructor. Invalid indexes are often used as parent indexes when referring to top-level items in a model.

Model indexes refer to items in models, and contain all the information required to specify their locations in those models. Each index is located in a given row and column, and may have a parent index; use row(), column(), and parent() to obtain this information. Each top-level item in a model is represented by a model index that does not have a parent index - in this case, parent() will return an invalid model index, equivalent to an index constructed with the zero argument form of the QModelIndex() constructor.

To obtain a model index that refers to an existing item in a model, call QAbstractItemModel::index() with the required row and column values, and the model index of the parent. When referring to top-level items in a model, supply QModelIndex() as the parent index.

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.

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

Returns the data for the given role for the item referred to by the index.

Qt::ItemFlags QModelIndex::flags () const

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

This function was introduced in Qt 4.2.

qint64 QModelIndex::internalId () const

Returns a qint64 used by the model to associate the index with the internal data structure.

See also QAbstractItemModel::createIndex().

void * QModelIndex::internalPointer () const

Returns a void * pointer used by the model to associate the index with the internal data structure.

See also QAbstractItemModel::createIndex().

bool QModelIndex::isValid () const

Returns true if this model index is valid; otherwise returns false. A valid index belongs to a model, and has non-negative row and column numbers.

See also model(), row(), and column().

const QAbstractItemModel * QModelIndex::model () const

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

QModelIndex QModelIndex::parent () const

Returns 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 is smaller than the other model index; otherwise returns false.

This function was introduced in Qt 4.1.

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. Note that all values in the model index are used when comparing with another model index.


Related Non-Members

typedef QModelIndexList

Synonym for QList<QModelIndex>.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Comment fermer une application

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.2
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web