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_METATYPE with using and same types

Q_DECLARE_METATYPE with using and same types

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 318 Views 2 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.
  • K Offline
    K Offline
    kkettinger
    wrote on last edited by kkettinger
    #1

    Hello,

    i'm having issues with Q_DECLARE_METATYPE. My header file:

    // ...
    namespace Storage
    {
    namespace Types
    {
    using tCommandValue = int;
    using tStateValue = int;
    using tEventValue = QVariant;
    }
    }
    

    They are registered with qRegisterMetaType:

    qRegisterMetaType<Storage::Types::tCommandValue>();
    qRegisterMetaType<Storage::Types::tEventValue>();
    qRegisterMetaType<Storage::Types::tStateValue>();
    

    The usage in signal/slots:

    void addEvent(const IDs::Events id, const Types::tEventValue value);
    

    Now when using no Q_DECLARE_METATYPE, i get this error:

    QObject::connect: Cannot queue arguments of type 'Storage::Types::tStateValue'
    (Make sure 'Storage::Types::tStateValue' is registered using qRegisterMetaType().)
    

    When i add the types with Q_DECLARE_METATYPE in my header file, i get a compile error:

    // ...
    Q_DECLARE_METATYPE(Storage::Types::tCommandValue);
    Q_DECLARE_METATYPE(Storage::Types::tEventValue);
    Q_DECLARE_METATYPE(Storage::Types::tStateValue); // <--- Error: redefinition of 'QMetaTypeId<int>'
    

    Maybe someone has an idea.
    Thanks!

    Best regards,
    Kevin

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kkettinger
      wrote on last edited by
      #2

      Found a solution. For POD-types that are already registered Q_DECLARE_METATYPE is not needed.
      qRegisterMetaType is still needed but needs an additional type name:

      qRegisterMetaType<Storage::Types::tStateValue>("Storage::Types::tStateValue");
      qRegisterMetaType<Storage::Types::tEventValue>("Storage::Types::tEventValue");
      qRegisterMetaType<Storage::Types::tCommandValue>("Storage::Types::tCommandValue");
      
      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        The "named" version is needed because you are not declaring a new type but in fact you are declaring an allias.

        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
        1

        • Login

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