Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSharedPointer in QML



  • 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?


  • Qt Champions 2018

    Your mistake is thinking it should be possible. It's not.

    Pass the object as a raw pointer.



  • okay. thanks


Log in to reply