Qt doesn't allow to register class template?
My class hierarchy is
TreeItemTemplateBackend : public QObject
template<typename T>
TreeItem : public TreeItemTemplateBackend
This is what i registred in qml:
qmlRegisterType<InspectorItem>("ge.gui", 1, 0, "InspectorItem");
qmlRegisterType<TreeItemTemplateBackend>("ge.gui", 1, 0, "TreeItemTemplateBackend");
qmlRegisterType<TreeItem<InspectorItem>>("ge.gui", 1, 0, "TreeItem");
I am still getting this error:
QMetaProperty::read: Unable to handle unregistered datatype TreeItem<InspectorItem>*
for property 'Inspector::root'
Inspector::root is:
Q_PROPERTY(TreeItem<InspectorItem> * root READ root NOTIFY rootChanged)
when you want to use a pointer to e.g. 'ClassA' in a Q_PROPERTY, you have to register it like this:
qRegisterMetaType<ClassA*>("ClassA*");
The solution might be more complex for you due to the use of templates, but hopefully this points you in the right direction.
(same as my other answer. source: 'jpn')
You have to do two things:
Q_DECLARE_METATYPE( ClassName* )
for each template realisation. Pay an attention on asterisk (*) in the end! Since you need to expose pointer, not the value. For example Q_DECLARE_METATYPE( ClassName<ItemClass>* )
. Look into documentation where to put this declaration the best (after class declaration out of all namespaces usually ). There are also issues with namespaces, so always use full qualified names here.qmlRegisterType<ClassName>(...)
or qmlRegisterUncreatableType<ClassName>(...)
if you need just expose some data with a property and not to instantiate it in QML. Here you don't need an asterisk, since you register not the pointer, but class itself.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With