[Interest] DelegateModel example doesn't work with raw JSON items?

Jason H jhihn at gmx.com
Thu Jun 30 20:38:01 CEST 2016


I'm following the example at: http://doc.qt.io/qt-5/qtquick-tutorials-dynamicview-dynamicview4-example.html with a few modifications: My data is JSON, I have only one lessThan function. I've been trying to get it to work but in the sorting comparison I was getting:
qml: {}, 31 // Object, index
qml: sortfunction distance {}, {}  //sortfunction is stance, left, right
qml: NaN < NaN false // comarison of left and right, and the result


I had been assigning the model as javascript items i.e.: model: [{..}, ... ]

On a whim I changed it to: model: ListModel {} // this is what the example was using
And added:
function toListModel(items) {
  visualModel.model.clear();
  for (var i=0; i<items.length; i++) {
    visualModel.model.append(items[i])
  }
}

And it started working. I also noticed that where I could use text: modelData.name in the delegate I could no longer do that and had to just use text: name

Is there a way I can have it work AND not have to run it through that function? Whenever I change the modelData I've got to run it through that silly function.













More information about the Interest mailing list