Hi,
I've tried both Q_DECLARE_METATYPE and qRegisterMetaType but I still get the unregistered type error
I had the same problem and was searching for a solution for days. In my case the data type is defined in a namespace (lets say MyNamespace) and i used the Q_PROPERTY macro as it is mentioned in the docs. The thing is that it is not mentioned that you must fully qualify your data type when using this macro.
So this line is wrong, although the compiler won't warn you or something:
Q_PROPERTY(MyClass customProperty READ getCustomProperty WRITE getCustomProperty)
Q_PROPERTY(MyClass customProperty READ getCustomProperty WRITE getCustomProperty)
To copy to clipboard, switch view to plain text mode
...but this line is correct:
Q_PROPERTY(MyNamespace::MyClass customProperty READ getCustomProperty WRITE getCustomProperty)
Q_PROPERTY(MyNamespace::MyClass customProperty READ getCustomProperty WRITE getCustomProperty)
To copy to clipboard, switch view to plain text mode
The message "QMetaProperty::read: Unable to handle unregistered datatype" comes from QMetaProperty::read() and this is the place where one should start to debug when this message appears. Here you can clearly see which QVariant or QMetaType call is returning wrong data.
When should I be calling qRegisterMetaType?
Thats easy to answer as it is mentioned on the docs, have a look at:
http://doc.qt.nokia.com/4.7-snapshot...sterMetaType-2
Also, to use type T with the QObject::property() API, qRegisterMetaType<T>() must be called before it is used, typically in the constructor of the class that uses T, or in the main() function.
Hope this helps.
So long
Daniel
Bookmarks