[Development] How to skip write property in qml's property binding?

JiDe Zhang zccrs at live.com
Fri Jul 19 07:31:54 CEST 2024


For an example:

Text {
    text: fooObject?.title
}

When the fooObject is null, will got a qml error "Unable to assign [undefined] to QString".

I don't want the error, so, how to skip write value for "text" property when fooObject is null?

Text {
    text: fooObject?.title ?? text
}

This is a workaround, but it is a magic, maybe will got a cycle binding?

Text {
    text: fooObject?.title ?? bypass
    objectName: {
       if (fooObject)
            return fooObject.name
       bypass
    }
}

This syntax will more easily understand.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20240719/ba93ddcd/attachment.htm>


More information about the Development mailing list