[Qt-qml] no basic property define confuse

Eduardo Fleury eduardo.fleury at openbossa.org
Thu Sep 30 05:30:22 CEST 2010


Yes, this works as well.

I understand, but I confuse this syntax problem.
>

Are you confused by the ":" vs "=" syntax?

If that's the question, then assume for a moment that you use ":" in QML
(like you did) but use "=" in inline JavaScript blocks (like I did inside
onClicked). There's a crucial difference between these since the former is a
"binding" and the latter an "assigment", but for now, consider that "parent"
is being successfully set in both cases.

Or is the confusion regarding the whole idea of setting the parent, etc?

If so, I'm not sure how familiar you are with standard C++ Qt but a little
bit of background on QGraphicsScene and QGraphicsItems (the base class of
QML items like rectangle and text) helps.

The idea is that in order to be painted on the screen an item needs to:

1) be created
2) have its "visible" property set to true
3) have a valid geometry, that means a non-zero size and be somewhere useful
on the screen.
4) be added to what we call the "scene", which is basically the set of items
that are handled by the system that paints things in Qt. In QML this is
almost hidden as implementation detail.

When we create an item in QML by default only conditions (1) and (2) are met
by default.
In the example I sent, I also set the size, so (3) is OK as well.

However it does not yet belong to a scene, and the way of making that happen
in QML is setting its parent. When this is done, the underground machinary
of Qt will make sure child knows about parent, parent knows about child and
that everyone is in the scene and shown... That's the reason parent needs to
be set.

Huh... but what about when we create items inside others, like:

Rectangle {
    Text {
        text: "foobar"
    }
}

In this case you don't set the parent of text and yet, it works. Well,
what's happening here is that by default, the inner items that are created
inside another item automatically becomes children of the outter one. In
this case, QML ensures that Text is a child of Rectangle (sets parent, adds
to scene, bla, bla) automatically. Kind of a (very important) syntactic
sugar.

Let me know if it makes sense!

BR,
Eduardo


-- 
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/20100930/c043bfab/attachment.html 


More information about the Qt-qml mailing list