On 28/06/2011, at 9:31 PM, ext Henry Gomersall wrote:

> The documentation for aliases
> (http://doc.qt.nokia.com/latest/qml-extending-types.html#default-properties)  
> presents the following example: 
> 
> // Button.qml
> import QtQuick 1.0
> 
> Item {
>     property alias buttonText: textItem.text
> 
>     width: 200; height: 50
> 
>     Text { id: textItem }
> }
> 
> with the comment:
> "In this case, the use of aliased properties is essential. If buttonText
> was not an alias, changing its value would not actually change the
> displayed text at all, as property bindings are not bi-directional: the
> buttonText value would change when textItem.text changes, but not the
> other way around."
> 
> My question is, why is using aliases in this example better than the
> following, which seems to achieve the same goal: 
> 
> // Button.qml
> import QtQuick 1.0
> 
> Item {
>     property string buttonText
> 
>     width: 200; height: 50
> 
>     Text { id: textItem; text: parent.buttonText }
> }
> 

The doc example is just a demonstration of how aliased properties behave 
differently to ordinary properties and how they can be linked directly to 
properties of child objects. In this case it's a very simple example, so the 
example you provided above can certainly achieve the same result. Where the 
alias properties may become useful is if the Text element's text property is 
changed from elsewhere within the the Button or Text, and these changes would 
then not be reflected in the buttonText property.

regards,

Bea
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Reply via email to