PDA

View Full Version : QMetaProperty::read: Unable to handle unregistered datatype in plugins



ksrarc
4th December 2008, 03:30
Hello, I have this problem.

I define an typedef of qreal as Real and make it available to QVariant with Q_DECLARE_METATYPE in an include file, lets say "typedefs.h"

Then create an abstract interface with:
Q_PROPERTY( Real nextReal READ nextReal )

Define then the Subclass and implement "nextReal" method. Create a plugin that create the subclass.

In the main.cpp of the application load the plugin, create a Subclass object and read the property using QObject::property and get this message:

QMetaProperty::read: Unable to handle unregistered datatype 'Real' for property 'AbstractInterface::nextReal'

but if it is readed with nextReal method works fine.

in both files main.cpp and AbstractInterface.h include typedefs.h

I need to use the QObject interface not the Abstract interface, how can I solve this?

jpn
4th December 2008, 17:12
Have you tried qRegisterMetaType()?

ksrarc
4th December 2008, 19:09
Yes, I have tried that, but when I print the result, it prints "0", not the real value, since the method returns non-zero reals. Any other ideas?

knicewar
26th April 2010, 23:59
I'm also trying to do the same thing. In my case, my custom plugin has a simple struct property with several double members: struct Foo { double a; double b; double c; }; I've tried both Q_DECLARE_METATYPE and qRegisterMetaType but I still get the unregistered type error when I run designer. Was there ever a solution given for this? When should I be calling qRegisterMetaType? I'm calling it in my plugin's constructor for lack of better place I could think of.

ViRuSTriNiTy
4th July 2012, 07:37
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)

...but this line is correct:


Q_PROPERTY(MyNamespace::MyClass customProperty READ getCustomProperty WRITE getCustomProperty)

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/qmetatype.html#qRegisterMetaType-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