Accessing QSortFilterProxyModel from QML
Unsolved
QML and Qt Quick
-
I have a Model created in C++, register in main as a singleton, and succesfully in use in a view in QML:
qmlRegisterSingletonType<GatewayModel>( "GatewayModel", 1, 0, "GatewayModelQML", [](QQmlEngine *eng, QJSEngine *js) -> QObject * { Q_UNUSED(js); eng->setObjectOwnership(GatewayModel::instance(), QQmlEngine::ObjectOwnership::CppOwnership); return GatewayModel::instance(); });
I now want my QML code to use a QSortFilterProxyModel sitting in front of my "GatewayModel". How do I insert the proxy inbetween my QML code and my model? (In C++? In QML?? How)
-
I think what you want is to set the source model.
proxyModel.setSourceModel(*instance of GatewayModel*);
And then just declare it in main:
engine.rootContext()->setContextProperty("ProxyModel", instance of ProxyModel);