In Qt/QML we have this syntax in models:
ListModel {
ListElement {name: 'Willian'; age: 21;}
}
// And we can access the values with this syntax
model.get(x).name // With each key in list
But my models are created in Qt using QStandartItemModel
, and I want access to it as to QML models, however I don't know how to do it. I had thought of operator overloading, but not exists overhead in operator .
(dot).
I know that we can access QStandartItemModel
via data(const QModelIndex & index, int role = Qt::DisplayRole)
, but QML version is lot more explicit.
Does somebody have an idea of how to do this?
You should use roleNames method to make some properties visible from QML. It allows you to bind your custom display role (int) to human readable name (visible from QML).
Entire article can be found here .