To Ulf’s point,

You would indeed not be able to restore a previous value using text: 
fooObject?.title ?? text because it will have been overwritten whenever 
fooObject?.title yields a valid value.
The most reasonable solution therefore is to use the Binding element which is 
designed to restore the previous/original binding or value of the binding 
target property whenever its “when” property is false.
It isn’t the most concise but it is bomb-proof and explicit, and is fully 
aligned to your requirements.


Text {
    id: yourTextObject

    text: "defaultString" // default binding when fooObject !== null; this 
could itself be a binding to some other default property.

    Binding { 
        yourTextObject.text: fooObject.title // assuming title will be valid if 
fooObject !== null, if not the “when” property might need fooObject?.title
        when: fooObject  // else it will be restored to being bound to the 
“defaultString" value
    }
}

Kind regards,

Mike
-- 
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to