Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Q_DECLARE_SMART_POINTER_METATYPE type restriction
QtWS25 Last Chance

Q_DECLARE_SMART_POINTER_METATYPE type restriction

Scheduled Pinned Locked Moved Unsolved General and Desktop
smart pointersqvariant
3 Posts 3 Posters 998 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.
  • J Offline
    J Offline
    Joel Bodenmann
    wrote on 28 Jan 2020, 19:47 last edited by
    #1

    I was investigating the idea of storing an std::shared_ptr<T> in a QVariant. This would allow me to put a shared pointer to my custom data int a QComboBox's data field.
    I'm aware of the existence of QSharedPointer. The data I am working with is only available wrapped into an std::shared_ptr (data provided by a 3rd party component). This leaves me with the choice of either storing raw pointers or registering my own type for the use with QVariant.

    For this, I've been looking at Q_DECLARE_SMART_POINTER_METATYPE. The documentation has the following to say about this macro:

    This macro makes the smart pointer SmartPointer known to QMetaType as a smart pointer. This makes it possible to put an instance of SmartPointer<T> into a QVariant, if T is a type which inherits QObject.
    

    I'd be interested to know why T would be restricted to a type which inherits QObject.
    Can anybody enlighten me?

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Jan 2020, 20:22 last edited by
      #2

      Hi,

      Pretty good question. I think it something you should bring to the interest mailing list where the Qt developers/maintainers can be found.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 28 Jan 2020, 21:07 last edited by
        #3

        From a short look at the code without understanding the whole stuff I would guess that internally there is only a QObject pointer is stored. So it must be a QObject to track the lifetime.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2

        2/3

        28 Jan 2020, 20:22

        • Login

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