Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ItemsSource = ObservableCollection<T> databinding in QML

ItemsSource = ObservableCollection<T> databinding in QML

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xamlwhizz
    wrote on 28 Feb 2013, 15:41 last edited by
    #1

    Hi,

    I have 2 viewmodels, FooViewModel and BarViewModel
    FooViewModel has a property QList<BarViewModel*> FooViewModel::items

    My 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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      milasch
      wrote on 5 Sept 2013, 20:20 last edited by
      #2

      Have u ever figured this out? If so, how did u manage to expose an "ObservableCollection" from your ViewModel?

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xamlwhizz
        wrote on 9 Sept 2013, 09:27 last edited by
        #3

        @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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved