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. [SOLVED] Q_DECLARE_METATYPE and Qt containers
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Q_DECLARE_METATYPE and Qt containers

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.7k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    frankiefrank
    wrote on last edited by
    #1

    It's a simple question but not evident from the docs at http://qt-project.org/doc/qt-5/qmetatype.html#Q_DECLARE_METATYPE

    Let's say I have a class called MyClass and I want to use QList<MyClass> with QVariant.

    Do I need to use only
    @
    Q_DECLARE_METATYPE(MyClass)
    @

    or

    @
    Q_DECLARE_METATYPE(QList<MyClass>)
    @
    (or a typedef of the above if I can't use templates).

    "Roads? Where we're going, we don't need roads."

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      IIRC, Qt has built-in support for that. But nothing beats a test :)

      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
      • F Offline
        F Offline
        frankiefrank
        wrote on last edited by
        #3

        Stay tuned :)

        "Roads? Where we're going, we don't need roads."

        1 Reply Last reply
        0
        • R Offline
          R Offline
          r1z1
          wrote on last edited by
          #4

          I'm wondering also. Should be mentioned in the documentation.

          So if I want to use MyClass in a QList and if I do that:
          @
          Q_DECLARE_METATYPE(MyClass)
          @

          I've got a compile error:
          @error C2039: 'qt_metatype_id' : is not a member of 'QMetaTypeId<T>'@

          But

          • If i do that
            @
            Q_DECLARE_METATYPE(MyClass)
            Q_DECLARE_METATYPE(QList<MyClass>)
            @

          No compile error.

          Maybe a specific include is missing or the QList declare is the only thing to do?

          1 Reply Last reply
          0
          • F Offline
            F Offline
            frankiefrank
            wrote on last edited by
            #5

            Tested my code and looks like it works even without specifically using the Q_DECLARE_METATYPE for the QList.

            @r1z1 I'm not sure about your problem. Maybe you want to open another thread and post exactly where you are putting the Q_DECLARE_METATYPE line.

            "Roads? Where we're going, we don't need roads."

            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