Search code examples
c++qtqmlqtquick2qt-quick

Is it possible to binding "properties" ranther than "property" in Binding?


I'm writing Binding for Loader's item. Let's start from my case after simplifying. Assuming that CustomItem is an customized item that has properties named prop1,prop2, and I use it as Loader's source component. When I want to initialize prop1 and prop2 in Loader, I have to do like

Loader {
    id: loader
    sourceComponent: comp
    Binding {
        target: loader.item
        property: "prop1"
        when: loader.status === Loader.Ready
        value: control.prop1
    }
    Binding {
        target: loader.item
        property: "prop2"
        when: loader.status === Loader.Ready
        value: control.prop2
    }
}

Is it possible to bind more value in one Binding? Note that you cannot

Binding {
    loader.item.prop1: control.prop1
    loader.item.prop2: control.prop2
}

Additionally, cna I initilize required property of source component?


Solution

  • Let me share the awesome solution from @GrecKo answered here

    Instantiator {
        model: ["prop1", "prop2"]
        delegate: Binding {
            target: loader.item
            property: modelData
            value: control[modelData]
       } 
    }