[Qt-qml] Writing to property alias

Eduardo Fleury eduardo.fleury at openbossa.org
Wed Sep 15 00:49:37 CEST 2010


On Tue, Sep 14, 2010 at 1:23 PM, Leonardo Cunha <leo.cunha at nokia.com> wrote:

> my question is whether writing to an alias property should override or not
> any binding existing on the aliased property


Hi Leo, IMO short answer is it should not. The rationale is the classical
Slider example..

== Slider.qml =================

Rectangle {
    id: background

    // This is a public property people can use to read/write current slider
value
    property alias sliderValue: knob.internalValue

    Rectangle {
        id: knob

        // This makes the knob move when somebody set the current slider
value
        x: internalValue * (background.width - knob.width)

        // This makes internalValue change when the knob is dragged. I need
this to be valid at all times, nobody can override it
        property real internalValue: knob.x / (background.width - knob.width

        MouseArea { drag, etc... }
    }
}

== Usage ========================

Item {

    Slider {
        id: slider
    }

    MouseArea {
        id: mute
        onClicked: slider.sliderValue = 0
    }
}

If the behavior you described was in place, then a click on the mute button
would invalidate the property binding internal to the Slider component. That
way it would no longer respond to knob dragging, ever.

For me this is the main usage of alias properties, to multiplex the data
entry points to a given variable. I create entry points that are used by the
component internally and leave one open for users to create bindings or set
values imperatively.


> 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).
>

Yep, I rely on that side-effect a lot. In the above example, the consistency
is ensured by the reverse binding acting on "knob.x", but indeed, without
that we could be in an inconsistent state.


> "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."


My understanding of an alias property. They _are_ property and thus have
their own name and "binding-slot". However they lack data storage and thus
forward all writes and reads to the target (original) property.


What about you? Do you have an use case? Or is it the sensation that
"something is wrong" or inconsistent with the other parts of Quick?

Cheers,
 --
Eduardo M. Fleury
OpenBossa - INdT
http://eduardofleury.com/
http://www.openbossa.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100914/b521bf13/attachment.html 


More information about the Qt-qml mailing list