Reputation: 7973
I want to pass an objects from one qml to other qml. I have a list model.
ListModel {
id:favouriteapp
ListElement {
id: 1
name:"ABSC"
title:"5:03pm"
description:"heloo-1"
icon1:"images/climate_icon.png"
icon2:"images/climate_icon.png"
pinStatus : false
isLoaded: false
}
ListElement {
id: 2
name:"GHTT"
title:"Home at 5:23pm"
description:"via Gaydon Road-2"
icon1:"images/navigation_icon.png"
icon2:"images/navigation_icon.png"
pinStatus : false
isLoaded: false
}
}
Now I want to pass each property of the ListElement
via string value to other qml.
How can I pass this entire ListElement
object to other qml.
Upvotes: 2
Views: 2900
Reputation: 704
As @folibis said, you need to give a correct id to your object
ListElement {
id: obj1
...
}
Here is MyFile.qml
to which you can pass the reference to your ListElement
object:
Item{
...
function myFunction(listElementObject){
//whatever you need to do with your object
}
}
And in the same QML file as the ListModel
you'll have
MyFile{
id: myFileId
}
Component.onCompleted: myFileId.myFunction(obj1)
Upvotes: 2
Reputation: 5207
You can always use favouriteapp.get()
to access any of the list elements as a JavaScript object and pass this object on to where ever you need it.
You could also allow the other component access to the model and let it access the list element it needs.
You could also have the other component provide a data object or separate properties and bind those in the place where you have access to the model.
Upvotes: 0