This is close but not quite right when the count changes the count property declared in the page doesn’t update correctly. Surely if the count doesn’t change during app life-cycle then example is fine. However, if it does change during app life-cycle then following changes would be needed
- Define readonly property to the C++ header:
Q_PROPERTY(int count READ count NOTIFY countChanged)
- Add public signal
void countChanged();
- Whenever you insert or remove items from the model
emit countChanged();
- Property binding changes to
property int count: model.count
Worth noting that if the same model is used by many pages / views you can declare the model itself inside the main.qml, something like this:
main.qml:
ApplicationWindow
{
initialPage: MyPage {
aNumber: model.count
}
cover: MyCoverPage {
aNumber: mount.count
}
DemoModel {
id: model
}
}
This would render the intermediate count property on the page unnecessary.