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. Using custom type in Q_PROPERTY

Using custom type in Q_PROPERTY

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpropertymocmeta-objects
1 Posts 1 Posters 459 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.
  • V Offline
    V Offline
    Venkateswaran
    wrote on 23 Oct 2020, 15:27 last edited by Venkateswaran
    #1

    I want to use custom type in Q_PROPERTY MEMBER. Please check out my below code.

    header.h

    class Custom {
      Q_GADGET
      Q_PROPERTY(int mode MEMBER mode STORED true)
    
     public:
      Custom();
      int mode;
    };
    
    class Test {
      Q_GADGET
      Q_PROPERTY(QString ip MEMBER ip STORED true)
      Q_PROPERTY(Custom discovery MEMBER discovery STORED true)
    
     public:
      Test();
      QString ip;
      Custom discovery;
    };
    
    Q_DECLARE_METATYPE(Custom)
    Q_DECLARE_METATYPE(Test)
    

    main.cpp

    
    #include "header.h"
    
    Test::Test() { qRegisterMetaType<Test>("Test"); }
    
    Custom::Custom() { qRegisterMetaType<Custom>("Custom"); }
    
    int main(int argc, char *argv[]) {
      QCoreApplication a(argc, argv);
      Test reg;
      return a.exec();
    }
    

    when I compile the above code it throws below error

    /home/venkat/Documents/test/testing/build-test-Desktop_Qt_5_12_4_GCC_64bit-Debug/moc_CustomeTypes.cpp:175: error: no match for ‘operator!=’ (operand types are ‘Custom’ and ‘Custom’)
    moc_CustomeTypes.cpp:175:31: error: no match for ‘operator!=’ (operand types are ‘Custom’ and ‘Custom’)
                 if (_t->discovery != *reinterpret_cast< Custom*>(_v)) {
                     ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    should I need to provide operator!= for Custom type ?

    1 Reply Last reply
    0

    1/1

    23 Oct 2020, 15:27

    • Login

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