QML Item: Binding loop detected for property "width"



  • Hi folks!
    I'm experiencing 'Binding loop' error and can't find where's the trouble. Compiler says: qrc:/main.qml:26:5: QML Item: Binding loop detected for property "width".
    Here's my code:

    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4
    
    ApplicationWindow{
        id: applicationWindow1
        width: container.width + 2*margins
        height: container.height + 2*margins
        title: "Lab5"
        visible: true
        property int margins: 4
    
        Connections{
            target: transitionPoint
            onSendDataToQml: {
                outputText.text = outStr
            }
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                transitionPoint.receiveDataFromQml(dataInputField.text)
            }
        }
    
        Item {
            id: container
            width: childrenRect.width
            height: childrenRect.height
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
    
            Text {
                id: outputText
                text: "Lambda"
                wrapMode: Text.WordWrap
                textFormat: Text.PlainText
                verticalAlignment: Text.AlignVCenter
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
            }
    
            TextField{
                id: dataInputField
                width: 110
                placeholderText: "enter fraction data"
                anchors.horizontalCenter: outputText.horizontalCenter
                anchors.top: outputText.bottom
                anchors.topMargin: 3
            }
        }
    }
    
    
    

    Any suggestions are appreciated :)



  • The binding loop comes from the container item where you ask the container to be of the size of its content whereas you size its content according to the parent size.

    You can either define the container dimensions as followed :

    width: dataInputField.width
    height: outputText.height + dataInputField.height
    

    but I would feel more natural to do the other way around : define the container dimension and then compute child element dimension according to the parent.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.