Important: Please read the Qt Code of Conduct -

Complex Data Model

  • Hello,
    I have an object named AVehicle that has two arrays - one of parts objects, and another of materials objects. I need to set up a QListView to display the parts, and a QTableView to display the materials. AVehicle is a subclass of QAbstractTableModel, and I have the ListView working. I don't know how to setup the delegate so that it will differentiate between the two Views.

    How should I handle this?


  • I think that you are doing your work at the wrong level. Why is AVehicle a QAbstractTableModel? Wouldn't it make much more sense to let AVehicle have a QAbstractTableModel? That also makes it easy to make the distinction between the two lists/tables you need to feed your data to.

    You should see the item models are merely an interface to your data, but they should not be the data object. Take a look at "this more detailed explanation": that I wrote down in the documentation.

  • That's where I was going wrong. Thanks!

  • Hello and sorry for bringing up this old thread, but I felt it's better than starting a new one.

    On several occasions, I ran into problems very similar to jwombie's. I always wondered how to use QAIM correctly. (Side note: unfortunately, Qt's design isn't helpful here: there are Qt models that are adapters ( e.g. QSqlTableModel) and Qt models that are data stores (e.g. QStringListModel))

    I always tended to create adapter models that provide a view into my data, however that may be stored. But then I quickly ran into problems. I would not be able to tell what models to notify if the underlying data had changed. A google search suggested that I was doing it wrong and I should just use one big QAIM to avoid synchronization problems :-(

    So my question is: if a QAIM is best used as an adapter, is there any "recommended practice" how to synchronize models?
    I'm afraid of using a single, huge QAIM. Trying to squeeze all of my data into a hierarchical table would quickly become ugly (I tried. I gave up).


Log in to reply