>
> as always, it depends. If  you really want to set a binding based on a
> condition, but otherwise leave the value as it is, you want to use
>
> Text {
>      Binding on text {  value: fooObject.title; when: fooObject }
> }
>

Note that the `when` only affects when the binding is applied to the target
property, not when the value property is evaluated.
The above code will result in "Cannot read property 'title' of null" when
fooObject is null, cf. https://bugreports.qt.io/browse/QTBUG-22005

Maybe work could resume on attempting to find a solution on this issue?

Meanwhile I think the best solution is `text: fooObject?.foo ?? ""`
This does assign an empty string but I think it does make sense and it is
clearer in this case.
For custom and complex properties you could use `undefined` instead and
potentially have a `RESET` function for a c++ defined `Q_PROPERTY`.

For more advanced use cases where you don't want to reset the value, use
Binding and restoreMode.

Cheers,
Pierre-Yves Siret
-- 
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to