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

Jérôme Godbout jerome at bodycad.com
Mon May 2 16:31:55 CEST 2016


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

Hope this help.

On Sat, Apr 30, 2016 at 3:35 PM, Sina Dogru <sinadooru at gmail.com> wrote:

>
>
> 2016-04-29 21:34 GMT+03:00 Jérôme Godbout <jerome at bodycad.com>:
>
>>
>> QmlObject
>> {
>>   readonly property alias myCategory: myCategory_
>>
>>   QmlObject
>>   {
>>      id: myCategory_
>>      readonly property color red: "#FF00000"
>>   }
>> }
>>
>
> Hello Jérôme,
>
> Can you please explain what would be different to use QtObject instead of
> QmlObject,
>
> QtObject {
>     readonly property alias myCategory: myCategory_
>
>     QtObject {
>         id: myCategory_
>         readonly property color red: "#FF0000"
>     }
> }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160502/5e895553/attachment.html>


More information about the Interest mailing list