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. Problem with binding in QML
Forum Updated to NodeBB v4.3 + New Features

Problem with binding in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 360 Views 3 Watching
  • 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.
  • M Offline
    M Offline
    msauer75
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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).

      (Z(:^

      1 Reply Last reply
      1
      • M Offline
        M Offline
        msauer75
        wrote on last edited by
        #3

        Hi,

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

        BR
        martin

        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