zhaoyk10
zhaoyk10

Reputation: 67

Binding loop detected for property "width" of Image

Let's assume I have a component like this:

Rectangle {
    id: rec1

    Rectangle {
        id: rec
        x:10;y:100; height:100;
        color: 'red'
        anchors {
            left: parent.left
            right: parent.right
        }
        Loader {
            id:loader
            width: parent.width
            sourceComponent: comp
        }

    }

    Component {
        id: comp
        Rectangle {
            anchors {
                left: parent.left
                leftMargin: 1           // this line
                right: parent.right
            }
            height:img.height
            Image {
                id: img
                source: '/myimage.png'
                width: parent.width
                fillMode: Image.PreserveAspectFit
            }
        }
    }
}

the console reports:

QML Image: Binding loop detected for property "width"

But if I change the comp leftMargin to leftMargin: 0 (not 1), everything is ok

Is this a bug or some feature I am missing?

Upvotes: 0

Views: 2671

Answers (1)

NG_
NG_

Reputation: 7173

In my opinion you made a typo:

width:100; height:100;
...
anchors {
    left: parent.left
    right: parent.right
}

By doing this you:

  1. Explicitly set your rectangles width (to 100).
  2. Do explicitly anchoring of left side to parents left side (if this is only one anchoring operation -- it is Ok) and then -- do anchoring of right side to parent's right side (so you are implicitly defining your rectangle's width).

It is contradiction. Try to solve it (for example, by removing right anchoring) and re-run your application.

Upvotes: 2

Related Questions