// ParentQml.qml Item{ id: defaultParent property bool randomBoolProperty DefautChild { // no id property bool prop1 property int prop2 property string prop3 property var prop4 enabled: parent.randomBoolProperty } property Item userChoice: useUserQml ? MyLovelyQml{} : someDefaultQml{} }
// MyLovelyQml.qml Column{ id:myLovelyQml property bool myUniqueProperty: true Component.onCompleted: { var defaultChild_Idx = 0 for (var i=0; i<parent.children.length; ++i){ // seaching for the child 'DefaultChild' by looking at all // the properties I know it has if ( (typeof parent.children[i].prop1 !== 'undefined') && (typeof parent.children[i].prop2 !== 'undefined') && (typeof parent.children[i].prop3 !== 'undefined') && (typeof parent.children[i].prop4 !== 'undefined')){ defaultChild_Idx = i; } } parent.children[defaultChild_Idx].enabled = Qt.binding(function() { return parent.randomBoolProperty && (typeof parent.userChoice.myUniqueProperty === 'undefined') // when user will change "userChoice", "myUniqueProperty" // will be undefined and only the value of // "randomBoolProperty" will matter }) } }