get method removed from XmlListModel
Solved
Qt 6
-
On Qt5 I was able to do something like this:
XmlListModel { id: model XmlRole { name:"prop1" } XmlRole { name:"prop2" } XmlRole { name:"prop3" } } onRowsInserted: { for (var i = 0; i < model.count; ++i) { if (model.get(i).prop2 === "testVal2") //do something } }
On Qt6 this is not possible anymore, as the getter is removed. I found a (in my opinion) workaround to still get the same result:
XmlListModel { id: model XmlListModelRole { name:"prop1" } XmlListModelRole { name:"prop2" } XmlListModelRole { name:"prop3" } } onRowsInserted: { for (var i = 0; i < model.count; ++i) { if (model.data(model.index(i,0), Qt.UserRole+1) === "testVal1") //do something } }
But if I remove or add XmlListModelRoles, I might also need to change the offset to Qt.UserRole.
So, why was the get method removed, and is there a better way to solve this? -
a suggestion to reimplement this has been created here:
https://bugreports.qt.io/browse/QTBUG-102267in the meantime this function can be used:
function get(i) { var o = {} for (var j = 0; j < roles.length; ++j) { o[roles[j].name] = data(index(i,0), Qt.UserRole + j) } return o }
-