1
votes

I've been trying to wrap my head around this one for a while and came up with a few hacks, but none of them seem to be the Right Way. Hopefully this makes sense. Say I have three qml files.

First QML:

...
ListView {
   id: patientList
   model: patientModel
   delegate: E3DPatientListItem {
       onClicked: {
           if (patientList.currentIndex !== index)
           {
                patientList.currentIndex = index
                detailStackView.push("DetailPanel.qml",
                     { "view": view, "ptInfo": model })

...

DetailPanel:

...
Page {
    property QtObject ptInfo
    Timeline {
        ptInfo: ptInfo // <- how do I pass this to Timeline?
...

Timeline.qml

...
Item {
    property QtObject ptInfo // <- always null :(
...
1
What about Timeline{ ptInfo: parent.ptInfo }? or Page { property alias ptInfo: timeline.ptInfo } ?Dinesh
I thought I had tried everything, but Timeline{ ptInfo: parent.ptInfo } does indeed work! Thank you very much.Cinder Biscuits

1 Answers

1
votes
...
Page {
    property QtObject ptInfo
    Timeline {
        ptInfo: ptInfo // <- how do I pass this to Timeline?
...

What do you suppose ptInfo: ptInfo is achieving? You are binding the property to its own identifier.

Maybe try not using the same identifier to avoid shadowing, or give the Page and id and then ptInfo: pageid.ptInfo. parent.ptInfo will also work as long as the object has the parent property exposed, keep in mind that QtObject does not.

However, you don't really need to have property QtObject ptInfo in Timeline.qml, as long as a timeline is always instantiated inside a page, you can access ptInfo directly from inside the timeline because of dynamic scoping. Note that dynamic scope properties will only work for properties that are defined in the root element of the particular qml file:

// Obj1.qml
Item {
  property int test: 7
  Obj2{}
}

// Obj2.qml
Item {
  Component.onCompleted: console.log(test) // it will work
}