[SOLVED] Dynamic instance of Binding Component on array element. Issue.
-
wrote on 25 Sept 2015, 07:08 last edited by billouparis
Hello,
I am stuck with an easy one:
*import QtQuick 2.2
Item {
id: idMain
Component {
id: bindingComponent
Binding {} } property variant list1: ["A", "B", "C", "D", "E"] property variant list2: ["a", "b", "c", "d", "e"] property variant list3: list1 Item { id: myRepeater Repeater { model: 5 Text { property alias idText: idText id: idText text: index } } } property variant objKeyBinding: [] function fnCreateBindings() { var i = 0 for (i = 0; i < 5; i++) { objKeyBinding[i] = bindingComponent.createObject( ) objKeyBinding[i].target = myRepeater.children[i].idText objKeyBinding[i].property = "text" objKeyBinding[i].value = list3[i] } } property bool bbool: false Timer { interval: 1000 repeat: true running: true onTriggered: { if (bbool === true) { list3 = list1 console.log("if "+myRepeater.children[0].idText.text) } else { list3 = list2 console.log("else "+myRepeater.children[0].idText.text) } bbool = ! bbool } } Component.onCompleted: { fnCreateBindings() }
}
The console output of this code leads to
qml: else A
qml: if A
qml: else A
qml: if AAnd I am expecting:
qml: else a
qml: if A
qml: else a
qml: if AWhat can I do to have an actual dynamic binding working there?
-
wrote on 25 Sept 2015, 08:59 last edited by
One colleague found a solution:
objKeyBinding[i].value = Qt.binding(function(){return list3[this]}.bind(i))
That's crazy!
Bill
1/2