Unfortunately, with all the normal magic of QML property bindings, getting a property updated in a setup that involves return values from functions isn’t really doable, like this:
|
1 2 3 |
Text { text: qtobject.calculatedValue() } |
I’m told there is a low priority feature request for a way of signalling that a function now returns a different value and all properties using it should be reevaluated.
I have so far discovered two different workarounds for that that I will be presenting here.
Using an extra property
Appending an extra property to trigger the reevaluation of the function is one way of doing it.
|
1 2 3 |
Text { text: qtobject.calculatedValue() + qtobject.emptyNotifierThing } |
with the following on the C++ side:
|
1 2 3 4 |
Q_PROPERTY(QString emptyNotifierThing READ emptyString NOTIFY valueChanged) QString emptyString() const { return QString(); } |
This is a bit more code to write and to remember to use, but it does get the job done.
Intermediate layer
Another way is to inject an intermediate layer, an extra object, that has the function. It can even be simplified by having a pointer to itself.
|
1 2 3 |
Text { text: qtobject.dataAccess.calculatedValue() } |
with the following on the C++ side:
|
1 2 3 4 |
Q_PROPERTY(QObject* dataAccess READ dataAccess NOTIFY valueChanged) QObject* dataAccess() { return this; } |
It seems a bit simpler for the reader on the QML side, but also gets the job done.
I am not sure which way is the best one, but the intermediate layer has a nicer feeling to it when more complicated types are involved.

