QML Direct fetch a model from C++
-
How can I make something like this:
ListView { ... model: model.getModel(); }If I for example have a Model which consists of Models. Or can I use setContextProperty for class with Models??
@Kofr Yes Ofcourse if using C++ models
- You can return a C++ model and assign it to
modelproperty - You can use
setContextPropertyto set C++ models and then access from QML
See http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html for more info.
- You can return a C++ model and assign it to
-
@Kofr Yes Ofcourse if using C++ models
- You can return a C++ model and assign it to
modelproperty - You can use
setContextPropertyto set C++ models and then access from QML
See http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html for more info.
- You can return a C++ model and assign it to
-
@p3c0 thx,
I need to have dinamically creating datamodels inside head Datamodel. What approach can I consider to pick up? so far I see only using QObjectList models but it will make me having to rewrite much code. -
@Kofr If I understood you correctly: you can keep a class
Datamodeland set it as a context property namemodeland this class will contain aQ_INVOKABLEfunctiongetModeland make it return you C++ model instance. -
@p3c0 yeah something like from QML
getModel(2);means that I want to get nested DataModel like this
QList <QAbstactListModelInheritedModel> List;return List.at(2);Shall I create a function which casts my model to QObject and returns this QObject?
@Kofr Yes it should work. May be require a list of pointers. Try out.
Shall I create a function which casts my model to QObject and returns this QObject?
Not needed.
modelproperty will understand any class subclassed fromQAbstractItemModelor its derivatives. -