Interdependent models in the Qt Model-View

How to implement interdependent models using the Qt Model-View framework? In particular, how can I create a model containing fields that reference data in another model? I want the data that has been changed / deleted in the first model to propagate to the dependent field in the second model.

Say, for example, I have a model called BookListModelthat contains a list of books. I have a second model called ReaderTableModel, which contains a list of readers (names) and the book they are reading. I would like these books to refer to the corresponding index BookListModeland any changes for distribution to the corresponding entry in ReaderTableModel.

Does Qt have a mechanism for this? Can I save QPersistentModelIndexinside another model?

+4
source share
1 answer

It might be good to consider how the data that your models adapt is related. If you allow models to update their data sources as they change and to update themselves as data sources change, you don’t have to worry about the interaction between your BookListModel and ReaderTableModel.

The sample will look like this: When BookListModel changes, it will update its data source containing the book data. You will then update the ReaderTableModel book data from this data source for each reader.

Qt . http://qt-project.org/doc/note_revisions/13/174/view

+3

All Articles