Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QSharedPointer in QML
Qt 6.11 is out! See what's new in the release blog

QSharedPointer in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxj
    wrote on last edited by maxj
    #1

    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?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

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

      Pass the object as a raw pointer.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        maxj
        wrote on last edited by
        #3

        okay. thanks

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved