[Interest] Pointers as Q_PPOPERTY

Sandro Andrade sandroandrade at kde.org
Sat Nov 2 21:31:41 CET 2013


On Mon, Oct 28, 2013 at 8:13 AM, Stephen Kelly <stephen.kelly at kdab.com> wrote:
> On Monday, October 07, 2013 09:55:53 Sandro Andrade wrote:
>> On Wed, Oct 2, 2013 at 11:18 AM, Stephen Kelly <stephen.kelly at kdab.com>
> wrote:
>> > On Wednesday, October 02, 2013 19:02:54 Дмитрий Козлов wrote:
>> >> Q_PROPERTY(Hull * hull READ hull)
>> >> Q_PROPERTY(Reactor * reactor READ reactor)
>> >> Q_PROPERTY(Shields * shields READ shields)
>> >>
>> >> This approach should work in your case.
>> >
>> > This will work with QML with Qt 5.2.
>> >
>> >  https://codereview.qt-project.org/#change,42703
>> >
>> > Before that, your Q_PROPERTY needs to be type QObject*.
>>
>> That's great. What about QList<NonQObject *> ? Do I still need to use
>> QQmlListProperty in Qt 5.2 ?
>
> Did you try it?
>
> I suggest trying to use it with the QVariant API and the QML API.

After digging a little bit about that I've realized that QList<QObject *>-typed
Q_PROPERTIES are successfully available for use as QML models even in Qt 5.1.1.

QList<QObject-derived *>-typed Q_PROPERTIES cannot be used as models, since
they aren't automatically converted to a JavaScript array (are rather
kept as QVariant(QList<QUmlProperty*>), for example).

It seems qmlRegisterType<T> requires T be derived from QObject, so
qmlRegister'ing QList<QUmlProperty*> isn't a solution.

Luckily, I'm using QList<QObject *> properties but this'd prevent
things working fine otherwise.

Any hint ?

Thanks,
Sandro

>
> Thanks,
>
> --
> Join us in November at Qt Developer Days 2013 - https://devdays.kdab.com
>
> Stephen Kelly <stephen.kelly at kdab.com> | Software Engineer
> KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
> www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
> KDAB - Qt Experts - Platform-Independent Software Solutions



More information about the Interest mailing list