Search code examples
qtqmlqt-quick

Listmodel issue in QML


I need to get the count of items in the array of my list Model, where array is the one of the element of the list. Kindly refer following code snippet for the same.

I need to get the count of 'lValues' in the list element. (for example in terms of C++ : sizeof. lValues[])

ListModel {
        id: primaryList
        ListElement {
            Color: "label"
            lValues: [
                ListElement { lValues: 20 },
                ListElement { lValues: 0  },
                ListElement { lValues: 50 },
                ListElement { lValues: 60 },
                ListElement { lValues: 35 },
                ListElement { lValues: 70 },
                ListElement { lValues: 80 }
            ]
    }
}

Thanks in adavnce


Solution

  • Is this what You want?

    ListModel {
            id: primaryList
            ListElement {
                Color: "label"
                lValues: [
                    ListElement { lValues: 20 },
                    ListElement { lValues: 0  },
                    ListElement { lValues: 50 },
                    ListElement { lValues: 60 },
                    ListElement { lValues: 35 },
                    ListElement { lValues: 70 },
                    ListElement { lValues: 80 }
                ]
        }
    }
    Text {
        text: primaryList.get(0).lValues.count
    }