Hi everyone,

I'm currently working on a library that defines several types and I want to be able to use them into the Qt's property system.

For instance, I have a ColorButton class containing a "tulipColor" field whose type is tlp::Color:

Qt Code:
  1. class TLP_QT_SCOPE ColorButton : public QPushButton {
  2. Q_OBJECT
  3. Q_PROPERTY(Color tulipColor READ tulipColor WRITE setTulipColor)
  4.  
  5. tlp::Color _color;
  6. public:
  7. explicit ColorButton(QWidget *parent = 0);
  8.  
  9. Color tulipColor() const;
  10.  
  11. protected:
  12. void paintEvent(QPaintEvent *);
  13.  
  14. public slots:
  15. void setTulipColor(const Color&);
  16. };
To copy to clipboard, switch view to plain text mode 

I declared the tlp::Color type using the Q_DECLARE_METATYPE macro and the qRegisterMetaType function:

Qt Code:
  1. Q_DECLARE_METATYPE(tlp::Color)
  2. // ........
  3. qRegisterMetaType<tlp::Color>("Color");
To copy to clipboard, switch view to plain text mode 

Then I use the following code:
Qt Code:
  1. QVariant value = QVariant::fromValue<tlp::Color>(tlp::Color(255,0,0));
  2. qWarning() << "User Type for value is: " << value.userType();
  3.  
  4. ColorButton* btn = new ColorButton();
  5. for (int i=0;i<btn->metaObject()->propertyCount();++i) {
  6. QMetaProperty prop = btn->metaObject()->property(i);
  7. qWarning() << "UserType for the " << prop.name() << " property is: " << prop.userType();
  8. }
  9.  
  10. btn->setProperty("tulipColor",QVariant::fromValue<tlp::Color>(Color(255,0,0)));
  11. btn->show();
To copy to clipboard, switch view to plain text mode 

And get the following output:

User Type for value is: 258
UserType for the tulipColor property is: 258
So the tulipColor property is correctly registered with a valid userType. But when I try to change the value using the setProperty method, it returns false and my setTulipColor method is never called.

Please help :/