There should be no need to register a metatype. All you need to do is call setContextProperty and pass the model by pointer:
QQmlContext* context = view->rootContext();
Use it in QML:
model: _rosterItemModel
By pointer, itβs important, since QObjects are not copied and copying them will still break the semantics (since they have an "identifier").
An alternative to registering the model directly is registering an instance of your main class and using Q_INVOKABLE. In MainClass:
Q_INVOKABLE RosterItemModel* rosterItemModel() const;
Registering an instance of mainClass (mainClassInstance is again considered a pointer):
context->setContextProperty( "_mainInstance", mainClassInstance );
In QML:
model: _mainInstance.rosterItemModel()
source share