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. Binding loop detected

Binding loop detected

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 4 Posters 9.6k 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.
  • K Offline
    K Offline
    kgregory
    wrote on last edited by
    #1

    I have some controls in my QtQuick app that set parameters in my object. For example, this slider below. I want it to initialize it's property value from the underlying C++ object but from then on, any adjustments to the slider should modify the C++ object.

    This code seems to get the job done, except that I keep getting 'binding loop detected' errors. So I'm assuming this is not the correct way to do it. Can anyone tell me the "proper" way to do this or how to get rid of the binding loop errors?

    Slider {
            id: sizeSet
            height: 0.4*parent.height
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: sizeText.right
            anchors.leftMargin: 0.02*parent.width
            anchors.right: parent.right
            anchors.rightMargin: 0.02*parent.width
            from: 1
            to: 300
            value: modelData.size
            onValueChanged: modelData.size=sizeSet.value
            handle: Rectangle {
                    x: parent.leftPadding*.95
                    y: parent.topPadding * .95
                    implicitWidth: parent.height*.5
                    implicitHeight: parent.height*.5
                    radius: parent.height*.25
                    color: parent.pressed ? "#f0f0f0" : "#ffffff"
                    border.color: "#C0C0C0"
                }
        }
    }
    
    raven-worxR E 2 Replies Last reply
    0
    • K kgregory

      I have some controls in my QtQuick app that set parameters in my object. For example, this slider below. I want it to initialize it's property value from the underlying C++ object but from then on, any adjustments to the slider should modify the C++ object.

      This code seems to get the job done, except that I keep getting 'binding loop detected' errors. So I'm assuming this is not the correct way to do it. Can anyone tell me the "proper" way to do this or how to get rid of the binding loop errors?

      Slider {
              id: sizeSet
              height: 0.4*parent.height
              anchors.verticalCenter: parent.verticalCenter
              anchors.left: sizeText.right
              anchors.leftMargin: 0.02*parent.width
              anchors.right: parent.right
              anchors.rightMargin: 0.02*parent.width
              from: 1
              to: 300
              value: modelData.size
              onValueChanged: modelData.size=sizeSet.value
              handle: Rectangle {
                      x: parent.leftPadding*.95
                      y: parent.topPadding * .95
                      implicitWidth: parent.height*.5
                      implicitHeight: parent.height*.5
                      radius: parent.height*.25
                      color: parent.pressed ? "#f0f0f0" : "#ffffff"
                      border.color: "#C0C0C0"
                  }
          }
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @kgregory said in Binding loop detected:

      value: modelData.size
      onValueChanged: modelData.size=sizeSet.value

      there you have the obvious loop

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • YashpalY Offline
        YashpalY Offline
        Yashpal
        wrote on last edited by
        #3

        @kgregory said in Binding loop detected:

        value: modelData.size
        onValueChanged: modelData.size=sizeSet.value

        This has a loop effect, slider value is dependent on modelData.size and modelData.size is dependent on slider value. Try to get rid of it.

        raven-worxR 1 Reply Last reply
        0
        • YashpalY Yashpal

          @kgregory said in Binding loop detected:

          value: modelData.size
          onValueChanged: modelData.size=sizeSet.value

          This has a loop effect, slider value is dependent on modelData.size and modelData.size is dependent on slider value. Try to get rid of it.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Yashpal
          and thats exactly the problem.
          The loop is already in your definition. The values can't be mutual dependent from each other.

          @Yashpal said in Binding loop detected:

          slider value is dependent on modelData.size and modelData.size is dependent on slider value

          Think about it it, this never can be (logically) correct.

          What are you actually trying to achieve?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • K kgregory

            I have some controls in my QtQuick app that set parameters in my object. For example, this slider below. I want it to initialize it's property value from the underlying C++ object but from then on, any adjustments to the slider should modify the C++ object.

            This code seems to get the job done, except that I keep getting 'binding loop detected' errors. So I'm assuming this is not the correct way to do it. Can anyone tell me the "proper" way to do this or how to get rid of the binding loop errors?

            Slider {
                    id: sizeSet
                    height: 0.4*parent.height
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: sizeText.right
                    anchors.leftMargin: 0.02*parent.width
                    anchors.right: parent.right
                    anchors.rightMargin: 0.02*parent.width
                    from: 1
                    to: 300
                    value: modelData.size
                    onValueChanged: modelData.size=sizeSet.value
                    handle: Rectangle {
                            x: parent.leftPadding*.95
                            y: parent.topPadding * .95
                            implicitWidth: parent.height*.5
                            implicitHeight: parent.height*.5
                            radius: parent.height*.25
                            color: parent.pressed ? "#f0f0f0" : "#ffffff"
                            border.color: "#C0C0C0"
                        }
                }
            }
            
            E Offline
            E Offline
            Eeli K
            wrote on last edited by
            #5

            @kgregory You can try

            Component.onCompleted: {
            sizeSet.value = modelData.size
            modelData.size = Qt.binding(function() { return sizeSet.value })
            }
            

            (Not tested.) See http://doc.qt.io/qt-5/qtqml-syntax-propertybinding.html for further info about Qt.binding.

            raven-worxR 2 Replies Last reply
            0
            • E Eeli K

              @kgregory You can try

              Component.onCompleted: {
              sizeSet.value = modelData.size
              modelData.size = Qt.binding(function() { return sizeSet.value })
              }
              

              (Not tested.) See http://doc.qt.io/qt-5/qtqml-syntax-propertybinding.html for further info about Qt.binding.

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #6

              @Eeli-K
              writing the same (problematic) definition just in another way results in the same issue ;)
              Again, this mutual dependency will never be solved, no matter what different code you are trying.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              E 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @Eeli-K
                writing the same (problematic) definition just in another way results in the same issue ;)
                Again, this mutual dependency will never be solved, no matter what different code you are trying.

                E Offline
                E Offline
                Eeli K
                wrote on last edited by
                #7

                @raven-worx @kgregory My code may be wrong, instead of "modelData.size =..." "onValueChanged: modelData.size = value" could be enough. Raven-worx, why do you say that? Of course "x: y; y: x" is circular, but setting one once in Component.onCompleted and leaving off the binding should solve it. Well, now I see I wasn't explicit about leaving off the two bindings and replacing them with the code, if that was the problem. Of course there should be only one binding at most.

                1 Reply Last reply
                0
                • E Eeli K

                  @kgregory You can try

                  Component.onCompleted: {
                  sizeSet.value = modelData.size
                  modelData.size = Qt.binding(function() { return sizeSet.value })
                  }
                  

                  (Not tested.) See http://doc.qt.io/qt-5/qtqml-syntax-propertybinding.html for further info about Qt.binding.

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @Eeli-K said in Binding loop detected:

                  Raven-worx, why do you say that?

                  because those 2 are still property bindings...

                  sizeSet.value = modelData.size
                  modelData.size = Qt.binding(function() { return sizeSet.value })

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  E 1 Reply Last reply
                  0
                  • raven-worxR raven-worx

                    @Eeli-K said in Binding loop detected:

                    Raven-worx, why do you say that?

                    because those 2 are still property bindings...

                    sizeSet.value = modelData.size
                    modelData.size = Qt.binding(function() { return sizeSet.value })

                    E Offline
                    E Offline
                    Eeli K
                    wrote on last edited by
                    #9

                    @raven-worx No, only the latter is. The first line isn't a binding, it's just setting the value. The one and only binding is made after that and there is no circularity.

                    raven-worxR 1 Reply Last reply
                    0
                    • E Eeli K

                      @raven-worx No, only the latter is. The first line isn't a binding, it's just setting the value. The one and only binding is made after that and there is no circularity.

                      raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on last edited by
                      #10

                      @Eeli-K
                      yep you are right. Stupid me, should have read it more precisely.
                      Sorry.

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kgregory
                        wrote on last edited by
                        #11

                        Thanks, Eeli. I think that will work.

                        1 Reply Last reply
                        0

                        • Login

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