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. Declare structs as metatype
Qt 6.11 is out! See what's new in the release blog

Declare structs as metatype

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 997 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by
    #1

    Hi,
    I try run below code:

        struct userDetails
        {
            QString description;
            QString userEmail;
    	QString comment;
        };
    
        struct companyDetails
        {
            QString name;
            QString address1;
            QString address2;
            QString address3;
        };
        Q_DECLARE_METATYPE(userDetails)
        Q_DECLARE_METATYPE(companyDetails)
    

    But I have errors:
    networkworker.h:78:5: Class template specialization of 'QMetaTypeId' must occur at global scope qmetatype.h:1768:8: explicitly specialized declaration is here

    Where I should use my code ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Damian7546
      wrote on last edited by
      #2

      Probably I should useQ_DECLARE_METATYPE outside my class:

      Q_DECLARE_METATYPE(MyClass::userDetails)
      Q_DECLARE_METATYPE(MyClass::companyDetails)
      
      H 1 Reply Last reply
      0
      • D Damian7546

        Probably I should useQ_DECLARE_METATYPE outside my class:

        Q_DECLARE_METATYPE(MyClass::userDetails)
        Q_DECLARE_METATYPE(MyClass::companyDetails)
        
        H Offline
        H Offline
        HaoTian
        wrote on last edited by
        #3

        @Damian7546 Did it work? I think the form you write was declaring as Namespace::Struct, not Struct::struct.

        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