PDA

View Full Version : Delegate not passing the correct index for the model



balisingh
26th October 2012, 04:36
I have a some code like follows, when i click on a list item in the view, there is a runtime error with model[index], i cant figure out why, in qt creator index is also highlighted blue & italicized like javascript:

somemodelpage.qml



page{
listview {
id: itemview
delegate: itemdelegate { }
model: cppmodel

function delegateClicked(index) {
model.folder = model[index].name;
}
}


itemdelegate.qml

Item {
id: root
...
mousearea {
onclicked: root.ListView.view.delegateClicked(index)
}

wysota
26th October 2012, 10:25
The problem probably is in the C++ model.

Urthas
27th October 2012, 09:09
I don't understand how delegateClicked can be written not with a formal parameter, but with an actual argument. I think you might try removing the delegateClicked function and Item's onClicked entirely, and writing itemdelegate { onClicked: model.folder = ... }.