QSharedPointer in QML
Solved
QML and Qt Quick
-
Hi
is it possible to use QSharedPointer or QPointer in QML via Q_PROPERTY?
I have declared an Class "Contact" which inherits QObject.
At the bottom of "Contact.h" i declared:
Q_DECLARE_METATYPE(Contact)
Q_DECLARE_METATYPE(QSharedPointer<Contact>)and in main.cpp:
qmlRegisterType<Contact>("mj.contact", 1, 0, "MContact");
qRegisterMetaType<QSharedPointer<Contact>>("MContactSP");but when i try to access any property of Contact in qml all values/propertys of Contact are 'undefined'
I think this should be possible but what is my mistake?
-
Your mistake is thinking it should be possible. It's not.
Pass the object as a raw pointer.