Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



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


Log in to reply