Quantcast
Channel: Active questions tagged qtquick2 - Stack Overflow
Viewing all articles
Browse latest Browse all 147

How to access delegate properties in ListView using index

$
0
0

I want to access delegate properties in ListView. I've tried with contentItem but sometimes it's undefined.

Here is my code:

ListModel {    id: modeldata    ListElement{        name:"don"        rank:1    }    ListElement{        name:"shan"        rank:2    }    ListElement{        name:"james"        rank:3    }    ListElement{        name:"jeggu"        rank:4    }}Component {    id: delegateitem    Row {        property int count: rank        Rectangle{            width: 100            height: 50            Text{                anchors.centerIn: parent                text: name            }        }    }}ListView {    id: listview    focus: true    anchors.fill: parent    model: modeldata    delegate: delegateitem    onCurrentIndexChanged: {        console.log("position",currentIndex)        console.log("property",contentItem.children[currentIndex].count);    }}

Problem invalid output at position 1:

qml: position 0qml: property 1qml: position 1qml: property undefinedqml: position 2qml: property 2qml: position 3qml: property 3

Viewing all articles
Browse latest Browse all 147

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>