ListView won't get updated when I change data in my custom model
-
Are you sure you're calling dataChanged() with the correct values?
-
@Christian-Ehrlicher I pass two QModelIndex objects, one initiated to the top left row and column of my change and one initiated to its bottom right. Via debugger, I can see that the values make sense. For example:
My model has 4 columns (fixed, doesn't change). If I append a new row and my model previously had 2 rows, What I see is:
topLeft -> 2, 0 bottomRight -> 2, 3
-
And is the parent correct?
-
@Christian-Ehrlicher my model is created once upon startup in main.cpp. I create it with my QGuiApplication as the parent. My ListView is also a child of this QGuiApplication. Is this the wrong way to do it?
-
The QModelndex you're passing to dataChanged() need a proper parent index: http://doc.qt.io/qt-5/model-view-programming.html#parents-of-items
-
@VRonin Maybe I've expressed myself badly, since I'm still a newbie in Qt. The ListView is created via QML. It's as basic as:
ListView { id: list model: myModel }
Maybe, when done like that, the parent of the ListView is not the application itself, which must be why you were surprised.
-
Can we finally see where and how you emit dataChanged()? And with which indexes?