Nominate our 2022 Qt Champions!

Binding expression for nested properties not working

  • If there is an object like this:

    import QtQuick 2.0
    import QtQml 2.0
    Rectangle {
        property QtObject props: QtObject {
            property color mainColor: "blue"
        color: props.mainColor

    And I use this object, properties of A instance's props properties (like prop.mainColor) can be read, imperative assigned to, assign to a binding. The problem is that binding expression does not work:

    import QtQuick 2.9
    import QtQml 2.0
    import QtQuick.Window 2.2
    Window {
        A {
            id: a
            anchors.fill: parent
            props.mainColor: "red" // <<< error
            Component.onCompleted: {
                a.props.mainColor = Qt.binding(function(){return "red"})  // <<< wo
                a.props.mainColor = "red"  // <<< works
                console.log(a.props.mainColor) // <<< works
        // Component.onCompleted works also in this scope

    error (if property QtObject props: QtObject{...}):
    Cannot assign to non-existent property "mainColor"

    error (if property var props: Item{...}):
    Invalid grouped property access

    Can someone explain why one can read the property (and assign) but not bind-assign?