Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.0
-
None
Description
E.g. C++ class has
class MyElement : public QObject { public: Q_INVOKABLE doStuff(MyElement *e) { qDebug() << e->objectName(); } }
In QML:
MyElement { id: obj } Component.onCompleted: obj.doStuff(obj)
Running this QML crashes as the pointer received in doStuff() is invalid.
Obviously MyElement has already been registered with qmlRegisterType(). Adding QML_DECLARE_TYPE(MyElement) made no difference.
The workaround is to make the pointer type a QObject* instead and then qobject_cast it to a MyElement* object. The pointer is then valid.