Copy qml list elements from one model to another
Solved
QML and Qt Quick
-
Hi All,
I have two list models
ListModel{id: nameModel} ListModel{id: selectedNameModel}
The name model is filled from the backend using the
nameModel.append({'name':'Sam','age':23}) nameModel.append({'name':'Tom','age':25})
On a click operation on the listview containing the nameModel, I want to populate the selectedNameModel.
Could you suggest the most efficient way to do so?
-
@Valerian, what you think about this:
ListModel{id: nameModel} ListModel{id: selectedNameModel} Listview{ // ... model: nameModel delegate: Component{ // for example Rectangle{ // ... MouseArea{ anchors.fill: parent onClicked: selectedNameModel.append(nameModel.get(index)) } } } }
-
@medyakovvit Thanks.. It worked..
-
@medyakovvit It works fine..
-
@medyakovvit said in Copy qml list elements from one model to another:
@Valerian could you check what will happen when you delete some item from nameModel previously added to selectedNameModel?
Seems no deep copy! .. appended items will be lost .. !