PDA

View Full Version : default properties that is not a QDeclarativeListProperty



ugluk
22nd January 2013, 11:12
Is it possible? All my attempts have failed, specifically:



class BSFontLoader
: public QObject
{
Q_OBJECT

Q_ENUMS(Status)

Q_PROPERTY(QVariantList sources READ sources WRITE setSources)
Q_CLASSINFO("DefaultProperty", "sources")

...
}


Doing:



FontLoader {
"example.ttf"
"bla.ttf"
}


Does not work.

Added after 19 minutes:

I see:



This marks property as the class's default property. property must be either an object property, or a list property.


But a QVariantList is neither.

anda_skoa
22nd January 2013, 12:49
Default property is about children in the element tree, so it can be either one object or a list of objects.
A list of value can already be mapped to the array annotation, e.g.



FontLoader {
sources: [ "example.ttf", "bla.ttf" ]
}


Cheers,
_

wysota
22nd January 2013, 13:47
I think this might (it's just a guess, I haven't checked it) also work:


class BSFontLoader
: public QObject
{
Q_OBJECT

Q_ENUMS(Status)

Q_PROPERTY(QVariant sources READ sources WRITE setSources) // note -- QVariant, not QVariantList
Q_CLASSINFO("DefaultProperty", "sources")

...
}

FontLoader {
id: fl;
[ "example.ttf", "bla.ttf" ]
}

FontLoader {
"example.ttf"
}

setSources() would then need to use QVariant::isList() to check whether one or more values have been set to it. The bad part of all solutions here is that you can't do this:

fl.sources.push("xyz") or similar (regardless if sources contains an array or not).