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.
Note: 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.
All these properties are read-only, as are their C++ counterparts.
Note: 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 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.
Note: QModelIndex to QPersistentModelIndex conversion happens when accessing the array elements because any QModelIndexList property retains reference semantics when exposed this way.
All these properties are read-only, as are their C++ counterparts. In addition, we also expose the following functions:
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 ItemSelectionModel.
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: