Setting Loader.active to false doesn't release item immediately

前端 未结 4 551
小鲜肉
小鲜肉 2020-12-22 09:05

I have a use case where depending on the presence or absence of a property value an object referencing it is either created or removed. I am using a Loader for

4条回答
  •  渐次进展
    2020-12-22 09:16

    You can also use Connections to connect to the Loader's onActiveChanged-event and break the binding there:

    Loader {
        id: ld
        active: false
        sourceComponent: Text {
            text: object.subObject.i
            font.pointSize: 20
    
            Connections {
                target: ld
                onActiveChanged: {
                    if (active) return
                    text = text // This will overwrite the binding by the last value of the property itself.
                }
            }
        }
    }
    

提交回复
热议问题