I’ve used a subclass of QSqlQueryModel to expose the data for a ListView in my QML project. I want to do both of these in the same time:
-
Expose the model to QML using
setContextProperty()with the model’s pointer. -
Leave the model in another thread so when I call the model
update()function (executing the last query to reflect the data changed in database), the model won’t block the UI when it’s requerying the database.
Is it possible? If not, what is the better solution?
My solution is: Subclass
QThread, pass theQmlApplicationViewerpointer to its contructor and inside the new classDatabaseQueryThread, I set the context property for the viewer there. This way, Qt will allow me to provide access to the query model directly by pointer.