簡體   English   中英

檢測到屬性“文本”的綁定循環

[英]Binding loop detected for property "text"

我的實現是跟蹤我是否已經放置了點 我正在努力實現以下目標: A • D • G • J • M • P • S • V • Z 檢查的屬性綁定,不知何故它不想 go 回到 0。我也嘗試使用本地 var,但它總是 0 或 1。我該如何解決這個問題? 我收到以下錯誤: 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  ? " • " : "")
            }
        }
    }
}

是的,通過更改root.check變量,QQmlEngine 將重新評估所有依賴的綁定,包括newLetters function 本身,從而導致綁定循環。

我一直在關注您最近的問題(想知道最終目標是什么),我認為您應該更改您的 newLetters function,以返回實際想要的文本而不是條件:

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 ""
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM