Congratulations to our 2022 Qt Champions!

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:

    and in main.cpp:
    qmlRegisterType<Contact>("", 1, 0, "MContact");

    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