Important: Please read the Qt Code of Conduct -

QML Binding Loop when childrenrect is used.

  • Hello,
    I have a simple application as below :

    import QtQuick 2.6
    import QtQuick.Window 2.2
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("App1")
        Item {
            id: panel
            anchors.verticalCenter: parent.verticalCenter
            anchors.verticalCenterOffset: 1
            visible: true
            width: childrenRect.width + 11
            Image {
                id: divider
                visible: true
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter

    Problem is i am seeing qml warning "qrc:/main.qml:10:5: QML Item: Binding loop detected for property "width"" on running this piece of code.

    If the horizontal and vertical centers are removed form the image, then the code runs without any error.

    But there are certain use cases in my actual applications where i wish to retain the horizontal and vertical positioners.

    Please help me in understanding binding loop warning upon using "childrenrect.width".

    Thanks in advance.

  • The Image calculates its horizontal center from the parent's horizontal center which I guess is calculated from its width but that comes from the child's width so there is a loop.

    This is just a wild guess so I hope others will clarify this and let us know where the source codes of the relevant QML definitions are.

  • Qt Champions 2017

    Use width: divider.width + 11.

    childrenRect looks comes with four parameters including x, y.

  • Moderators


    Image has also a sourceSize property. you could use that, to get the Image's width

  • @dheerendra Thanks a lot!.. Worked alright for me..

  • @Laszlo-LG thank you for the explanation

Log in to reply