QML derived class - cannot assign qobject to base
-
wrote on 8 May 2016, 22:38 last edited by MartinD 5 Aug 2016, 22:43
Hi,
in C++ I have Derived class which is derived from Base class. I register Base class type to QML:qmlRegisterType<Base>("My", 1, 0, "Base");
In another class I have two properties:
Q_PROPERTY(Base *first WRITE firstSet) Q_PROPERTY(Base *second READ secondGet)
In C++ I store Derived object pointer to second.
In QML, I want to assign second to first. However, this produces:
qrc:/MyFile.qml:10: Error: Cannot assign QObject* to Base*
Is there a way QML can handle this assignment without error? I don't want to register Derived type to QML.
-
wrote on 9 May 2016, 08:24 last edited by
Almost every object in QML context is a QObject so you need also derive your Base class from QObject.
-
Almost every object in QML context is a QObject so you need also derive your Base class from QObject.
wrote on 9 May 2016, 14:44 last edited by@Tim.Jenssen Sorry that I didn't mentioned it but the Base class is derived from QObject. Still, it is not possible to assign pointer to object of Derived type (stored in Base type property) to BASE type property.
1/3