QQmlListProperty<const QObjectDerived> (notice 'const'): is it feasable somehow?

99 Views Asked by At

I have declared a QML-accessible list property of QObject derived types, and in form without 'const' it works fine:

Q_PROPERTY(QQmlListProperty<QObjectDerived> items READ items NOTIFY updated)

But with 'const' modifier:

Q_PROPERTY(QQmlListProperty<const QObjectDerived> items READ items NOTIFY updated)

there is unregistered type error on QML side.

Is it feasable somehow to use the second variant?

P.S. I'm using so-called const-propagation, so need to return const-pointers in the list.

1

There are 1 best solutions below

1
On

You need to call Test::registerQml() in your main

class Test : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QQmlListProperty<QObjectDerived> items READ items CONSTANT)

public:

    inline QQmlListProperty<QObjectDerived> items()
    {
        return QQmlListProperty<QObjectDerived>(this, data);
    }

    static void registerQml()
    {
        qmlRegisterType<QObjectDerived>("QObjectDerived", 1, 0, "QObjectDerived");
    }
};