Suppose on C++ side I've created a QList<QObject *> myObjects
which contains several custom objects derived from QObject
.
And then expose it to QML by setContextProperty( "myModel", QVariant::fromValue( myObjects ) );
The question is, in my QML code, how can I get and use a specific element (by index) in myModel
(which is a QList
). For instance, I would like to take a random element from the list and show it?
The example is here: http://doc.qt.io/qt-5/qtquick-models-objectlistmodel-example.html, where all elements of the model are shown in a ListView`, while I just want to show one (or several) of them.
QList<>
types as described in this document. So C++ array will be converted to common JavaScript array. See it here – folibis