[Qt-qml] Writing to property alias
Leonardo Cunha
leo.cunha at nokia.com
Tue Sep 14 18:23:16 CEST 2010
hi,
my question is whether writing to an alias property should override or not
any binding existing on the aliased property (currently the binding
continues active on the aliased property after writing to the alias
property).
Here is an example of a component with a property alias, let's call it
MyComp, the one below:
import Qt 4.7
Rectangle {
id: root
property alias myWidth: root.width
height: 50
width: parent.width
color: "tomato"
}
and then the main qml file is:
import Qt 4.7
Rectangle {
width: 100; height: 100
color: "black"
MouseArea {
anchors.fill: parent
onClicked: { myComp.myWidth = 50 }
}
MyComp {
id: myComp
myWidth: 50
}
}
If you execute the main file and click, I was expecting both assignments on
myWidth to override the existing binding on root.width, but the binding set
inside the component (root.width: parent.width) is still active (if you
resize the window, MyComp will resize too).
Is the current behavior intentional? It has a side-effect of protecting the
internal bindings of the components, while still allowing the user of the
component to do 'random' writes on the alias property (although these writes
might invalidate the binding until the binding is re-evaluated).
This is inconsistent with every other variable assignment case in qml, which
will clear any previous binding on that variable.
The docs about property alias
(http://doc.trolltech.org/4.7-snapshot/qml-extending-types.html) are also
not clear what is the expected outcome in this case, but this part "Read
operations on the aliasing property act as read operations on the aliased
property, and write operations on the aliasing property as write operations
on the aliased property." indicates that there should be minimal differences
to writing to an alias or the aliased property itself.
br,
// leo
--
Leonardo Cunha
Software Engineer
Nokia, Qt
More information about the Qt-qml
mailing list