test me
test me

Reputation: 47

Binding loop detected for property "text"

My implementation is to keep track of whether I have placed the dot already . I am trying to acheive the following: A • D • G • J • M • P • S • V • Z. The property binding for check, somehow it doesn't want to go back to 0. I also tried using a local var, but it will always be 0 or 1. How can I resolve this? I get the following error: Binding loop detected for property "text"

import QtQuick 2.15
import QtQuick.Window 2.15
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle {
        id: root
        visible: true
        anchors.fill: parent


        property string letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        property int check: 0

        readonly property real dx: 20

          function midpoint(idx) {
            return 20 + idx * root.dx;
          }

        function newLetters(index) {
              if(root.letters[index] === "A"){
                  root.check = 0
                  return true
              }
              if(root.letters[index] === "D"){
                  root.check  = 0
                  return true
              }
              if(root.letters[index] === "G"){
                  root.check  = 0
                  return true
              }
              if(root.letters[index] === "J"){
                  root.check  = 0
                  return true
              }
              if(root.letters[index] === "M"){
                  root.check = 0
                  return true
              }
              if(root.letters[index] === "P"){
                  root.check = 0
                  return true
              }
              if(root.letters[index] === "S"){
                  root.check = 0
                  return true
              }
              if(root.letters[index] === "V"){
                  root.check  = 0
                  return true
              }
              if(root.letters[index] === "Z"){
                  root.check  = 0
                  return true
              }
              else {
                root.check  = root.check + 1
              }
          }

        Repeater {
            model: 26
            Text {
                anchors.horizontalCenter: parent.left
                anchors.horizontalCenterOffset: root.midpoint(index)
                anchors.verticalCenter: parent.verticalCenter

                text: root.newLetters(index) ? root.letters[index] : (root.check === 0  ? " • " : "")
            }
        }
    }
}

Upvotes: 0

Views: 3084

Answers (1)

Amfasis
Amfasis

Reputation: 4208

Yes, by changing the root.check variable, the QQmlEngine will re-evaluate all bindings dependent on, including the newLetters function itself, thus leading to a binding loop.

I have been watching your recent questions (wondering what the end-goal is) and I think you should alter your newLetters function, to return the actual wanted text instead of the condition:

function newLetters(index) {
    if(index < 24) //below Y, everything is regular
    {
        if(index % 3 == 0)
            return root.letters[index]
        if(index % 3 == 1)
            return " ° "
    }
    else if(index == 24) //Y
    {
        return ""
    }
    else if(index == 25) //Z
    {
        return root.letters[index]
    }
    
    return ""
}

Upvotes: 1

Related Questions