[Development] Property bindings in Qt 6

Ville Voutilainen ville.voutilainen at gmail.com
Thu Sep 26 20:50:15 CEST 2019

On Thu, 26 Sep 2019 at 21:08, Pierre-Yves Siret <py.siret at gmail.com> wrote:
> I feel like custom getters and the ability to mark a property dirty are needed too.
> You might have a property that's provided by an outside system, and you maybe don't want to query it every time it changes, only when there's an observer bound to that property.
> About the
>     QProperty<QString> fullname;
>     fullname.setBinding([&]() { return surname() + " " + lastname(); });
> Does it store a QString internally and modify it whenever surname & lastname changes thus taking some space in memory or is it just evaluated lazily and never stored?

Based on my reading of the code, it does store a QString, but it will
modify it only if you get the property's value at least once. Also,
based on my reading, subsequent
modifications happen only if the dependent properties are changed,
since it bookkeeps dependency tracking information via thread-local
binding state,
which is the magic bit that makes lazy evaluation of the dependencies
tick. The lambda passed to setBinding looks like it's executing
arbitrary code that has no statements
of dependencies, but due to the thread_local state, the dependencies
are tracked automatically.

Right, Simon?

More information about the Development mailing list