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]How do you use an object list in a Repeater?

[SOLVED]How do you use an object list in a Repeater?

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 852 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rolias
    wrote on last edited by
    #1

    I'm trying to better understand data models in QML. That is I'm not looking for work-arounds to this question. The documentation for the Repeater object states that in addition to ListModels you can use

    • A string list
    • An object list

    as the model providing data for a repeater. I'm wondering how the delegate is supposed to use the model for both cases.
    For example, given this code :

    @
    property var objectList: [
    { "name": "Eirik", "category": "Qt" },
    { "name": "Haavard", "category": "Qt" }
    ]

    Repeater{
    model : objectList
    delegate : delegateId
    }

    Component{
    id: delegateId
    Text{
    text:??? //name doesn't work
    }
    }
    @

    If I want to display the name property of the object what would I specify for the text property in the example where the ??? is? Neither name, model.name works. I can use objectList[index].name but I could do that even if objectList weren't specified as the model. I figure these data model sources are mentioned as usable by Repeater for a reason but unfortunately I have yet to find or craft an example that works.

    Someone with the power should feel free to delete this post. The answer is in the docs. I just didn't scroll up. Under the delegate property it points out that there is a modelData property available when a string list or object list is used. Sorry for wasting the bandwidth.

    Check out my third course in the trilogy on Qt
    "Integrating Qt Quick with C++"
    http://bit.ly/qtquickcpp
    published by Pluralsight

    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