Reputation: 9
The reference demo is like this:
TreeView {
TableViewColumn {
title: "Name"
role: "fileName"
width: 300
}
TableViewColumn {
title: "Permissions"
role: "filePermissions"
width: 100
}
model: fileSystemModel
}
I want to change the fileSystemModel
to my self-defined model. How I should do this? Thanks.
Upvotes: 0
Views: 271
Reputation: 5207
You can export your model the same way the example is exporting "fileSystemModel".
Basically the steps are
Example assuming a locally defined QQuickView view
but QQuickWindow
or QQmlApplicationEngine
would result in very similar code:
MyModel model;
view.engine()->rootContext()->setContextProperty("_identifierForModel", &model);
The first argument of setContextProperty() is the name that is visible on the QML side, i.e. it works like the value if an "id" property in QML.
Upvotes: 2