[Interest] Clean way to define and categorize constants in QML

Sina Dogru sinadooru at gmail.com
Tue May 3 07:49:27 CEST 2016


2016-05-02 17:31 GMT+03:00 Jérôme Godbout <jerome at bodycad.com>:

> Hello Sina, this will not work (at least up to 5.5 as far as I know).
> Cause QtObject doesn't have a default property to place children like Item
> have. You would get the following error while parsing your script:
> *Cannot assign to non-existent default property*
>
> You can either make a simple object that have the default property for
> children and property parent like Items (here's the QmlObject) or simply
> use the Item {} and get the extra position,dimension properties.
>
> class QmlObject : public QObject, public QQmlParserStatus
> {
>         Q_OBJECT
> Q_INTERFACES(QQmlParserStatus)
>         Q_CLASSINFO("DefaultProperty", "children");
>
> Q_PROPERTY(QQmlListProperty<QObject> children READ children NOTIFY
> childrenChanged STORED false);
>         Q_PROPERTY(QObject* parent READ parent WRITE set_parent NOTIFY
> parentChanged STORED false);
>
> Q_PROPERTY(QString idName READ id_name NOTIFY idNameChanged STORED false);
>       ...
> };
>
> Thank you so much Jérôme, I like the idea that categorizing the constants.
I was not aware that childing the QtObjects are not possible because of the
default property. Also thank you for showing the basic structure for
QmlObject.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160503/35b57521/attachment.html>


More information about the Interest mailing list