QMetaProperty::read: Unable to handle unregistered datatype 'TreeItem*'

后端 未结 2 1297
离开以前
离开以前 2021-01-12 01:12

Qt doesn\'t allow to register class template?

My class hierarchy is

TreeItemTemplateBackend : public QObject

template
TreeItem :          


        
2条回答
  •  清歌不尽
    2021-01-12 01:27

    You have to do two things:

    1. Register your type with macro 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* ). 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.
    2. Register each template realisation with qmlRegisterType(...) or qmlRegisterUncreatableType(...) 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.

提交回复
热议问题