[Solved] Calculation in a QML file?
-
Hello all,
I got the following code that doesn't work (in a QML file - PixelAdapter.qml) :
@Item {
id: pixelAdapterIdproperty int in property int alpha property int out out = in * 10 + alpha
}@
I tried :
@pixelAdapterId.out = pixelAdapterId.in * 10 + pixelAdapterId.alpha
PixelAdapter.out: PixelAdapter.in * 10 + PixelAdapter.alpha@
but everything doesn't work. I feel like I'm not doing something usual in QML but I HAVE to do some calculations with my properties, and "bind" the result of it to another property.
What do I have to modify ?Thanks in advance for any help,
Gui -
@Item {
id: pixelAdapterIdproperty int in: 10 property int alpha: 20 property int out: in * 10 + alpha
Component.onCompleted: {
console.log(out);
}
}@This example print 120 to console
-
This seems to work but it doesn't... I'll try to explain.
The thing is that in my software uses 2 bindings with this QML file. One binding is on the "in" value and the other on the "out" value.
And when I start my software, when I FIRST change my "in" value, the bind on the "out" value gets the new value. This works.
But when I change the value again, the "out" doesn't update... and the thing is that the value will constantly change in my software :/Does someone got an idea about it ?
-
For every property in QML you automatically get chadged signal, so you can try use something like:
@Item {
id: pixelAdapterIdproperty int in property int alpha: 20 property int out ..... function calcOut() { out = in * 10 + aplha } onInChanged: { calcOut() } .....
}@
-
[quote author="Thanana" date="1318406351"]This seems to work but it doesn't... I'll try to explain.
The thing is that in my software uses 2 bindings with this QML file. One binding is on the "in" value and the other on the "out" value.
And when I start my software, when I FIRST change my "in" value, the bind on the "out" value gets the new value. This works.
But when I change the value again, the "out" doesn't update... and the thing is that the value will constantly change in my software :/Does someone got an idea about it ?[/quote]
Use @Behaviour on in { /* some code here */ }@ It will be invoked every time when you change "in".
-
Both works, thanks a lot to both of you :)