[Qt-qml] What´s the correct QML type for arrays?
Adriano Rezende
adriano.rezende at openbossa.org
Mon Sep 6 16:40:10 CEST 2010
Hi,
> Also I would expect default properties to work with the list<> syntax. E.g.:
> Item {
> default property list<Item> items
> }
> But, doing that results in an "Unexpected token `<' " error.
> Anyways, I´m still very unexperienced with QML, so if someone knows, why
> this behavior makes sense, please let me know :)
Just non-default properties accepts 'template' declarations according
to QML grammar (I don't know why either). The two possible ways of
declaring a default property is as follows ("T_*" are tokens):
T_DEFAULT T_PROPERTY type identifier
Ex: default property Item foo
T_DEFAULT T_PROPERTY type identifier T_COLON expression
Ex: default property alias foo : bla.bar
Another question is why default properties does not accepts basic
types, like string, int and others.
I think this syntax is tricky, because 'default' can be seen just as a
type modifier, like 'private' or 'protected', that could be just
omitted in a property declaration, but internally it's creating
another path in the syntax tree.
According to the current syntax, the following lines are syntactically correct:
default property alias x
default property alias x : (1 + 2)
default property string x
default property string x : "hello"
But it will break in the semantic analysis.
In my opnion, it would make more sense if alias were a reserved word,
instead of being handled like a property type. The syntax could be
straight forward like this:
modifiers* T_ALIAS identifier T_COLON qualified_id
Ex: alias x : foo.bar
The advantages in the grammar are the follows:
- Enforces the target of the alias (no empty target is allowed)
- Don't let the user to put whatever he wants in the right side (expressions)
- Make clear distinction between properties and alias
Another tricky thing is that only qml types are recognized inside the
list type. So if you place:
property list<string> values
It will break, but if you place:
property list<Item> values
It works fine. This is something that will confuse a lot of developers.
BTW, Maybe it's a good idea to expose the QML grammar in the docs. I
think this will help a lot of developers.
Br,
Adriano
More information about the Qt-qml
mailing list