Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Correct structure of application model in Qt - multiple QAbstractItemModels?
Forum Update on Monday, May 27th 2025

Correct structure of application model in Qt - multiple QAbstractItemModels?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    x6herbius
    wrote on 25 Apr 2015, 13:29 last edited by
    #1

    For my application that deals with 3D data, I'm going to need to provide data in multiple different representations - for example, perhaps including an octree of renderable objects, or a list of all objects of a specific type. I understand that the QAbstractItemModel interface represents the application model, but should this be used as the one and only way to interact with the data itself, or is it OK to utilise it for each different representation in the more general application "model"?

    In other words, should I use:

    • One QAbstractItemModel overall, with each different data representation as a sub-table, and where a view chooses which model index to use as the root, or

    • One QAbstractItemModel per data representation, where a view uses setModel() to choose the representation to display?

    Thanks.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 25 Apr 2015, 13:40 last edited by Chris Kawa
      #2

      Both solutions are viable. It's just balancing between how costly is to copy(synchronize) data between the models and how complex the models would be with singular underlying data. That's something you will have to answer yourself.

      Another possibility is a single base model to interact with data and another thin model layer based on QAbstractProxyModel. Two subclasses of that type can be used to represent the same data in a different way for each view and share the underlying model.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        x6herbius
        wrote on 28 Apr 2015, 01:36 last edited by
        #3

        I hadn't seen QAbstractProxyModel, so I'll have a look at that and see if it looks like it'll work. I'm thinking that having singular data would be more efficient, since some data will need to reference other data anyway and managing this in several different places would be a massive pain.

        X 1 Reply Last reply 29 Apr 2015, 15:07
        0
        • X x6herbius
          28 Apr 2015, 01:36

          I hadn't seen QAbstractProxyModel, so I'll have a look at that and see if it looks like it'll work. I'm thinking that having singular data would be more efficient, since some data will need to reference other data anyway and managing this in several different places would be a massive pain.

          X Offline
          X Offline
          x6herbius
          wrote on 29 Apr 2015, 15:07 last edited by
          #4

          @x6herbius I also have a supplementary question: let's say I want to store a list of 3D meshes in the model, and so I create a tree structure similar to a directory tree. A child item of the root model item represents a non-leaf node labelled "Meshes", and all children of this node correspond to 3D mesh items.

          Would it be better to write a class for a 3D mesh item and store instances of this class in the "Meshes" sub-items, or to use the sub-items themselves to store the individual data components relevant to a mesh? In the latter case this might include another non-leaf node called "Vertices" whose child items are all QVector3D objects, or a non-leaf node called "Faces" whose children are model indices pointing to "Vertices" items.

          The advantage to the latter, as far as I can see, would be that the interface remains consistent throughout the model - if you want to change a vertex position on a mesh, you can index the position using a QModelIndex like anything else, instead of needing to know about the functions that some Mesh3D object might expose to you. This would be helpful to me as my application needs to be built to cater to extension (if other objects are implemented down the line) and to make the data it holds flexible. However, it might be difficult to ensure that you are accessing what you think you are accessing - there's no guaranteed structure, so anything could potentially be added as a child of the "Vertices" node, and no type safety - and the process might be slower than just using classes as conversion to/from QVariant.

          1 Reply Last reply
          0

          1/4

          25 Apr 2015, 13:29

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved