Asynchronously populating a QAbstractItemModel not working
-
I am implementing an QAbstractItemModel which fetches data asynchronously over a slow connection. From what I read the methods in QAbstractItemModel should return a response immediately, which can be overwritten later. So I built a simple QAbstractItemModel overriding only rowcount and data.
My algorithm is:
Upon rowCount() called return cached value or 0 if never fetched before
Fetch rowCount from remote slow database
Upon receipt of response issue beginInsertRows and endInsertRows
That works, but the data method is never called. So my 3 items in the view are empty. Why is 'data' not called for each item?...I originally posted this in the QML forum but per suggestion maybe it belongs here instead.
-
I am implementing an QAbstractItemModel which fetches data asynchronously over a slow connection. From what I read the methods in QAbstractItemModel should return a response immediately, which can be overwritten later. So I built a simple QAbstractItemModel overriding only rowcount and data.
My algorithm is:
Upon rowCount() called return cached value or 0 if never fetched before
Fetch rowCount from remote slow database
Upon receipt of response issue beginInsertRows and endInsertRows
That works, but the data method is never called. So my 3 items in the view are empty. Why is 'data' not called for each item?...I originally posted this in the QML forum but per suggestion maybe it belongs here instead.
@ocgltd
You may not get a good response with just this explanation and no code. For examplesimple QAbstractItemModel overriding only rowcount and data
This does not appear to meet the minimum requirements of Model Subclassing Reference as per https://doc.qt.io/qt-5/model-view-programming.html#read-only-access.
I also don't understand when you your
rowCount()
ceases to just return 0. But that may be a detail.Your "slow" model also might benefit from implementation of the "fetch more" interface.
A lot of people would suggest you test your implementation via QAbstractItemModelTester Class before you proceed any further.