Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] Accessing Repeater model in delegate
QtWS25 Last Chance

[Solved] Accessing Repeater model in delegate

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.6k 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.
  • S Offline
    S Offline
    stevenhurd
    wrote on last edited by
    #1

    Is there a way to access a Repeater's model in a delegate as you can with ListViews? For example:

    @Repeater {
    model: cppModel
    delegate: MyComponent {}
    }

    // in MyComponent.qml
    Rectangle {
    id: wrapper
    ...
    Button {
    onClicked: // want to directly access the C++ model here rather than have to send a signal to parent component
    }
    ...
    }@

    I've tried what has worked for ListViews...namely:
    @wrapper.Repeater.view.model.someSlot()@

    1 Reply Last reply
    0
    • frederikF Offline
      frederikF Offline
      frederik
      wrote on last edited by
      #2

      You could try to give the Repeater an id and accessing that.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stevenhurd
        wrote on last edited by
        #3

        It's been a while but I'll update what I ended up doing for anyone else interested...

        The reasoning behind trying to do the above was mainly that I wanted as little coupling as possible between the view (in this case a Repeater) and the delegate. Since I'm reusing my delegates in several views I didn't want to use a set view id. So basically I just provided the model as a property of the delegate component. Basically something like this:

        @
        Repeater {
        model: cppModel
        delegate: MyComponent {
        delegateModel: cppModel
        }
        }
        @

        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