Unable to assign [Type] to [Type] in QML
-
Hello,
I have a QObject derived class
MainViewModel
. I register this class as followsQ_DECLARE_METATYPE(MainViewModel*);
, inside a namespace namedViewModel
.
I also register the type so I can use it explicitily in QML:
qmlRegisterUncreatableType<MainViewModel>(PROJECT_NAME, MAJOR_VERSION, MINOR_VERSION, "MainViewModel", UNCREATABLE_REASON);
.In QML:
readonly property MainViewModel model: _model
// where _model is the propery passed to the QQmlEngineApplication.In the QML output, I get a warning:
Unable to assign ViewModel::MainViewModel to ViewModel::MainViewModel
.When I change the assign type to var such as:
readonly property var model: _model
Everything works as intended.
Any idea on what's missing ?
thanks
-
Which Qt version? I think this should work in 5.15+
-
@riodoro said in Unable to assign [Type] to [Type] in QML:
hi,
you can use only basic types in qml object properties.That's wrong. I'm using custom types since ages. As long as a type inherits from QObject, it can be used as property in QML.