Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Dynamic instance of Binding Component on array element. Issue.

[SOLVED] Dynamic instance of Binding Component on array element. Issue.

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 536 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    billouparis
    wrote on 25 Sept 2015, 07:08 last edited by billouparis
    #1

    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 A

    And I am expecting:
    qml: else a
    qml: if A
    qml: else a
    qml: if A

    What can I do to have an actual dynamic binding working there?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      billouparis
      wrote on 25 Sept 2015, 08:59 last edited by
      #2

      One colleague found a solution:

      objKeyBinding[i].value = Qt.binding(function(){return list3[this]}.bind(i))

      That's crazy!
      Bill

      1 Reply Last reply
      0

      1/2

      25 Sept 2015, 07:08

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved