Model/View and Custom Data Models - Data in the backend
-
So i am trying to learn more about the model view concept. So far i have read into Qt's documentation and also had a look at a few tutorials i have found online.
I do understand the basic concept of model view. I have whatever view, e.g. a table view and some data that i want to show in the table view. I don't want the data to be duplicated, thats why i implement a custom model that is an interface for my data. So far so good.
When i create a custom Model i could give it a ptr to my actual data structure in the background. So the model gives the data to the view via the "QVariant data(const QModelIndex& index, int role = Qt::DisplayRole)" function. I could also use the model on more than one view and they would stay synchronised.
Now what i do not fully understand is i have a ptr in the model to access my backend data. When i change the backend data and do not use "insertRows" or "removeRows" the data is not updated in the view(s). Then why would i seperate the data from the model in the first place? Is the correct way to store the data in the custom model and only use it through the model? that does not really make sense to me.
-
@tiegert said in Model/View and Custom Data Models - Data in the backend:
When i change the backend data and do not use "insertRows" or "removeRows" the data is not updated in the view(s).
When you don't know that something changed and nobody tells you - what would you do? Looking for a change periodically is not really a solution.
-
@Christian-Ehrlicher
So the correct way of working on the data it is, to only access the data through the model. Thanks -
You can add custom functions to e.g. bulk-add data to the model but must not forget the call the appropriate changed signals. This is a common way of adding data since it's to slow through setData() when a lot of stuff is changing.