Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with binding in QML



  • Hello,

    I have a QML textedit element, which get the value from my C++ programm with a Q_PROPERTY

        Q_PROPERTY(gc::data::IntDecorator                       *ui_filterRadius        MEMBER  FilterRadius        CONSTANT)
    

    I have the following code in my QML form:

    Item {
        property IntDecorator radius
        property int widthValue
        property bool setWidthValue
        property int radiusValue
    
        id: koordFilterRoot
    
        Row {
            width: parent.width
            spacing: Style.spacingRow*2
    
            Flow {
                width: parent.width
    
                Rectangle {
                    id: labelRadius
                    Text {
                        id: textRadius
                        anchors {
                            fill: parent
                        }
                        text: radius.ui_label
                        verticalAlignment: Qt.AlignVCenter
                    }
                }
    
                Rectangle {
                    id: labelTeRadius
                    TextEdit {
                        id: textEditRadius
                        anchors {
                            fill: parent
                        }
                        text: radius.ui_value
                        color: Style.colourDataSelectorFont
                        font.pixelSize: Style.pixelSizeDataControls
                        verticalAlignment: Qt.AlignVCenter
                       onEditingFinished: radiusValue = textEditRadius.text
                    }
                }
            }
        }
    
        Binding {
            target: radius
            property: "ui_value"
            value: radiusValue
        }
    }
    

    After loading of the form, the value of radius.ui_value = 0, although the member is in my constructor initalized with 20. I don't have any idea if the value will be set to 0, if I add the binding block?
    Can you help me with this problem?

    Thank you
    BR
    martin


  • Moderators

    Doesn't that work?

    property IntDecorator radius: radiusValue
    

    BTW. your property definition is wrong. See the docs. From the code you have pasted here, your property name is ui_filterRadius and not radiusValue you use in QML.

    Also BTW. to use a property in QML, you need to also specify the object (unless you added radiusValue as root context property).



  • Hi,

    thank you for your help. That works. I have to set the init value.

    BR
    martin


Log in to reply