IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QModelIndex and related Classes in QML

Qt Qml Models Reference Documentation.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QModelIndex and related Classes in QML

Since Qt 5.5, QModelIndex and QPersistentModelIndex are exposed in QML as value-based types. Also exposed in a similar fashion are QModelIndexList, QItemSelectionRange and QItemSelection. All objects from these types can be passed back and forth between QML and C++ as var properties or plain JavaScript variables.

Below you will find an overview of the API exposed to QML for these classes. For more information, refer to their C++ documentation.

Since all these types are exposed as gadgets, there are no property change notification signals emitted. Therefore binding to their properties may not give the expected results. This is especially true for QPersistentModelIndex.

QModelIndex and QPersistentModelIndex Types

All these properties are read-only, as are their C++ counterparts.

The usual caveats apply to QModelIndex in QML. If the underlying model changes or gets deleted, it may become dangerous to access its properties. Therefore, you should not store any QModelIndex objects. You can, however, store QPersistentModelIndexe objects in a safe way.

QModelIndexList Type

QModelIndexList is exposed in QML as a JavaScript array. Conversions are automatically made from and to C++. In fact, any JavaScript array can be converted back to QModelIndexList, with non-QModelIndex objects replaced by invalid QModelIndexes.

QModelIndex to QPersistentModelIndex conversion happens when accessing the array elements because any QModelIndexList property retains reference semantics when exposed this way.

QItemSelectionRange Type

All these properties are read-only, as are their C++ counterparts. In addition, we also expose the following functions:

QItemSelection Type

Similarly to QModelIndexList, QItemSelection is exposed in QML as a JavaScript array of QItemSelectionRange objects. Conversions are automatically made from and to C++. In fact, any JavaScript array can be converted back to QItemSelection, with non-QItemSelectionRange objects replaced by empty QItemSelectionRanges.

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+