Hi

I'm struggling to get my own class registered in the Meta-Object system. Here is my class:

Qt Code:
  1. namespace MyNamespace{
  2. class ObserverProperty : public QObject
  3. {
  4. Q_OBJECT
  5.  
  6. public:
  7. ObserverProperty(const QString& property_name = QString(), QObject* parent = 0) : QObject(parent) {
  8. observer_map = new QMap<QString,QVariant>;
  9. setObjectName(property_name);
  10. }
  11.  
  12. ObserverProperty(const ObserverProperty& observer_property) {
  13. observer_map = new QMap<QString,QVariant>(observer_property.observerMap());
  14. setObjectName(observer_property.objectName());
  15. setParent(observer_property.parent());
  16. }
  17. ~ObserverProperty() {}
  18.  
  19. inline QMap<QString,QVariant> observerMap() const { return *observer_map; }
  20.  
  21. protected:
  22. QMap<QString,QVariant>* observer_map;
  23. };
  24.  
  25. }
To copy to clipboard, switch view to plain text mode 

And I register the class using the following call, at the bottom of the header file:

Qt Code:
  1. Q_DECLARE_METATYPE(MyNamespace::ObserverProperty);
To copy to clipboard, switch view to plain text mode 

I want to set this class as a property on a QObject, and the following piece of code works:

Qt Code:
  1. QVariant prop;
  2. prop = obj->property(property_name.toStdString().data());
  3. if (prop.isValid() && prop.canConvert<ObserverProperty>()) {
  4. // Ok it exists.
  5. }
To copy to clipboard, switch view to plain text mode 

But If I understand correctly, I need to call the following to be able to create a QVariant with my class in it:

Qt Code:
  1. qRegisterMetaType<MyNamespace::ObserverProperty>("ObserverProperty");
To copy to clipboard, switch view to plain text mode 

And then create a QVariant with my class in it in the following way:

Qt Code:
  1. ObserverProperty observer_property("My Property");
  2. QVariant property= qVariantFromValue(observer_property);
  3. obj->setProperty(observer_property.objectName().toStdString().data(),property)
To copy to clipboard, switch view to plain text mode 

Now the problem is, I get the following error when compiling the qRegisterMetaType() call.

Qt Code:
  1. error: expected constructor, destructor, or type conversion before '(' token
To copy to clipboard, switch view to plain text mode 

I can't figure out why this is. Is is perhaps because of something wrong in my class? Or perhaps something to do with namespaces.

Any help will be much appreciated.

Thanks,
Jaco