Qt QML has a ListModel that can be used to represent list data. It provide a number of methods for adding elements to the list but the only method I can find for retrieving an element is the get() method that expect an index.
What is I want to check if my ListModel contains a particular element? Is there a way to recieve ListElement object(s) using a key and value?
For example connsider this list:
ListModel {
id: fruitModel
ListElement {
name: "Apple"
cost: 2.45
}
ListElement {
name: "Orange"
cost: 3.25
}
ListElement {
name: "Banana"
cost: 1.95
}
}
Is there a method such as fruitModel.get({name: "Banana"}) that would find elements with the name "Banana" and return them?
for(var i = 0; i < mylistModel.count; ++i) { if (mylistModel.get(i).name === name2search) { doSomething(mylistModel.get(i)); } }- Alexander V