ItemsSource = ObservableCollection<T> databinding in QML
-
wrote on 28 Feb 2013, 15:41 last edited by
Hi,
I have 2 viewmodels, FooViewModel and BarViewModel
FooViewModel has a property QList<BarViewModel*> FooViewModel::itemsMy problem is, I want to bind items to a Repeater::model, but all I get is:
@QMetaProperty::read: Unable to handle unregistered datatype 'QList<BarViewModel*>' for property 'FooViewModel::items'@
Does QList<T> fire up notifications when the collection changes, or do I need to do it myself?
Raising a Foo:itemsChangedEvent manually on QList<T>::append or QList<T>::removeOne seems a bit ineffective as it would cause Repeater to recreate the entire scene graph for the collection when only 1 item is added or removed from the "observed" QList<T>.any thoughts how to implement this?
-
wrote on 5 Sept 2013, 20:20 last edited by
Have u ever figured this out? If so, how did u manage to expose an "ObservableCollection" from your ViewModel?
-
wrote on 9 Sept 2013, 09:27 last edited by
@milasch there's a sample project that demonstrates the binding plus a bit Caliburn Microey View resolution using a custom 'ContentControl' class for 'Repeater::ItemTemplate' (actually it is called 'Repeater::delegate'):
https://github.com/bitterskittles/QtMvvmDemo
I wouldn't use it in a project though, mainly because when 'itemsChanged' is signalled, the 'ItemsControl' (in this case it is 'Repeater') destroys all Views ('ContentControl') bound through data binding and recreates them. Personally I'd prefer a proper 'INotifyCollectionChange' mechanism that allows signaling changes per individual item inside the collection, but I wasn't compelled enough to implement one.