Solved Order of qRegisterMetaType calls affects program behaviour
-
@kshegunov
Thank you - I've overseen the note until now. But i think that this hint is not really meant literally.If you see the text above:
"This function requires that T is a fully defined type at the point where the function is called. For pointer types, it also requires that the pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able to register pointers to forward declared types."This would mean that
typedef TestPropertyObject* TestPropertyObjectPtr; qRegisterMetaType<TestPropertyObjectPtr>("TestPropertyObjectPtr");
would be ok even there is no difference to that former pointer type.
Nevertheless, your hint
int meta_prop_type = meta_prop.userType(); //< !!! QMetaProperty::userType() !!!
fixed the problem. So thank you again ...BR
-
@ttuna said:
Thank you - I've overseen the note until now.
Don't worry, I have been known on occasion to overlook notes in the documentation as well. It happens to all of us.
"This function requires that T is a fully defined type at the point where the function is called. For pointer types, it also requires that the pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able to register pointers to forward declared types."
Well, I don't pretend to know the meta-object system intimately, however I believe this is remarked because of the dynamic creation of objects capabilities. Probably it's needed when QMetaObject::newInstance is employed. So I'd stick to what the documentation says and do it like:
typedef TestPropertyObject * TestPropertyObjectPtr; qRegisterMetaType<TestPropertyObject *>(); qRegisterMetaType<TestPropertyObjectPtr>("TestPropertyObjectPtr");
Or:
typedef TestPropertyObject * TestPropertyObjectPtr; qMetaTypeId<TestPropertyObject *>(); //< This calls qRegisterMetaType<TestPropertyObject *>(); internally qRegisterMetaType<TestPropertyObjectPtr>("TestPropertyObjectPtr");
Nevertheless, your hint int meta_prop_type = meta_prop.userType(); //< !!! QMetaProperty::userType() !!! fixed the problem. So thank you again ...
You're welcome. From what I could discern QMetaProperty::type returns
QVariant::UserType
for all user types, and that's why you need to call int QMetaProperty::userType() to get the correct type identifier.Kind regards.
-
@kshegunov was faster than me :) But basically yes, the example was a bit over-engineered.
Note that with Qt 5, there's no need to give a name at all when calling qRegisterMetaType unless you are registering a typedefed class.