[Interest] how can I call qRegisterMetaType?

Hamish Moffatt hamish at risingsoftware.com
Tue May 17 01:47:18 CEST 2016


On 17/05/16 01:27, Thiago Macieira wrote:
> On segunda-feira, 16 de maio de 2016 13:28:09 PDT Nye wrote:
>>> Should I just do it from the constructor?
>> That would be what I usually do. Still there's overhead of repeatedly
>> registering the same type, so if you have a better place on hand (a root
>> object/entry point of your application/library) that'd be better.
> The overhead is almost null because the inline parts of qRegisterMetaType
> function check whether it's already registered before calling the non-inline
> parts.

How about QMetaType::registerConverter? The documentation says all 
QMetaType functions are thread-safe. Is it also fast enough to call 
repeatedly?


>
> PS: DO NOT use the qRegisterMetaType overload with 1 argument. Use the one
> with zero.

What's the difference? When is the one with the char* typeName parameter 
needed?

I have a Q_PROPERTY of type QList<MyClass::MyEnum>, and I find that if I 
call

qRegisterMetaType<QList<MyEnum>>();

(ie without a typeName parameter), then I am unable to read the property 
through QMetaProperty::read(), and a message is printed: "Unable to 
handle unregistered data type 'QList<MyEnum>' for property 
'MyClass::propertyName'". Adding the name parameter solves it. However a 
QList<int> property works without giving a name.

And do I need to call 
Q_DECLARE_METATYPE(QList<MyQuestion::QuestionType>) or not? It doesn't 
seem to be necessary in my test cases.



Hamish



More information about the Interest mailing list