Passing QAbstractListModel to QML
-
Hi,
I have created a c++ class derived from QAbstractListModel and registered (using root context) same with QML to display a data on the ListView. I am able to successfully do that. Usually we do register on main.cpp to let QML know about the class.
The problem i have is on the model in QML, i need to filter the data on model by its type. So when i start filtering i need to clear the model and fetch data from database and loads back to model again. This is time consuming and at the same time my UI freezes until data is loaded. So i understud as my class is kept on main.cpp it resides on main thread and operation on that class will behave so.My implementation is as follows:
on main.cpp:EventStatusModel *eventModel = EventStatusModel::instance(); viewer.rootContext()->setContextProperty("eventModelObject", eventModel);
on QML:
ListView{
model: eventModelObject
}So here on the model when i start filtering , i have created a worker thread which will access EventStatusModel and clear its data and fetches data from tables and loads back to EventStatusModel.
Hope i have explained situation well. Here i need to know whether i can use any approaches to avoid freeze on UI
Regards
Bala B