[GH-ISSUE #62] Support for ObservableCollection<> #37

Open
opened 2026-05-05 11:00:39 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @pauldotknopf on GitHub (Aug 19, 2018).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/62

You can set the Repeater.model property with an array, but it doesn't auto-update when the collection changes. You have to reset the property with the same value.

Repeater.model will internally check if the type being set is a QQmlInstanceModel, and if it is, it will auto-update itself when signals are raised on the model.

We should create derived type implementing QQmlInstanceModel that carries a .NET ObservableCollection<> instance. And events raised on the .NET collection will raise the signals on the QQmlInstanceModel. This will allow us to bind lists to Repeater and ListView QML components and have them automatically update/render when items are added/removed/updated.

Originally created by @pauldotknopf on GitHub (Aug 19, 2018). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/62 You can set the ```Repeater.model``` property with an array, but it doesn't auto-update when the collection changes. You have to reset the property with the same value. ```Repeater.model``` will internally check if the type being set is a ```QQmlInstanceModel```, and if it is, it will auto-update itself when signals are raised on the model. We should create derived type implementing ```QQmlInstanceModel``` that carries a .NET ```ObservableCollection<>``` instance. And events raised on the .NET collection will raise the signals on the ```QQmlInstanceModel```. This will allow us to bind lists to ```Repeater``` and ```ListView``` QML components and have them automatically update/render when items are added/removed/updated.
Author
Owner

@visoplan-clemens commented on GitHub (Jan 20, 2021):

Hi,
we forked qmlnet for our application and it works not bad, so thanks for the great work!
Because we have a lot of lists in our application and updating the hole list each times leads to some noticeable performance problems we need to implement the support for the ObservableCollection and I would be happy to share the result when we're done and if it fits into your concept.

My idea was to implement it more or less the same way the support for arrays and list are implemented using the NetListModel. So basically creating a facade that implements the QAbstractListModel and that subscribes (using the NetTypeInfo, currently don't know exactly how but doesn't seem to be that complicated) to the events of the ObservableCollection and using the QAbstractListModel methods/signals to propagate these further to QML.

You are writing something about QQmlInstanceModel. Can you maybe explain a bit more what you mean, because I don't get the idea.

I also took a look into the PR regarding Model(AbstractItemModel) https://github.com/qmlnet/qmlnet/pull/215 but they doesn't look that usefull for me regarding this task. They seem to target more the usecase to implement an own class in C# that wants to use the AbstractItemModel features.

It would be great if you could give me some hints if there are some major things I overlooked or another approach would be better.

best regards

<!-- gh-comment-id:763817690 --> @visoplan-clemens commented on GitHub (Jan 20, 2021): Hi, we forked qmlnet for our application and it works not bad, so thanks for the great work! Because we have a lot of lists in our application and updating the hole list each times leads to some noticeable performance problems we need to implement the support for the ObservableCollection and I would be happy to share the result when we're done and if it fits into your concept. My idea was to implement it more or less the same way the support for arrays and list are implemented using the NetListModel. So basically creating a facade that implements the QAbstractListModel and that subscribes (using the NetTypeInfo, currently don't know exactly how but doesn't seem to be that complicated) to the events of the ObservableCollection and using the QAbstractListModel methods/signals to propagate these further to QML. You are writing something about QQmlInstanceModel. Can you maybe explain a bit more what you mean, because I don't get the idea. I also took a look into the PR regarding Model(AbstractItemModel) https://github.com/qmlnet/qmlnet/pull/215 but they doesn't look that usefull for me regarding this task. They seem to target more the usecase to implement an own class in C# that wants to use the AbstractItemModel features. It would be great if you could give me some hints if there are some major things I overlooked or another approach would be better. best regards
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/qmlnet#37
No description provided.