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. QAbstractItemModel and external data
Forum Updated to NodeBB v4.3 + New Features

QAbstractItemModel and external data

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 200 Views 1 Watching
  • 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.
  • N Offline
    N Offline
    nenchev
    wrote on last edited by nenchev
    #1

    I know this has been asked before but I can't seem to find enough information on the topic in order to feel confident in my understanding here. I have some data that I would like display in a QTreeView. The model that I am creating to interface between the data and the tree-view does not, and I strongly feel that it SHOULD NOT own that data. To me it seems like the entire concept of models is specifically designed to sit between the data store and the views, rather than acting as a data-store in itself. With that said, the docs state that begin/end-InsertRows() must be called around the data modification itself so:

    1. I don't want to expose public versions of the begin/end methods because that smells really bad.
    2. I don't want to hand off the responsibility of modifying the data-store to the model itself, as I believe that breaks the separation of concerns in my application.
    3. I'm considering connecting the model with the code that modifies the data-store via signals so that the model can handle the begin/end at the appropriate times, as notified by signals. This feels like I'm directly fighting with the intended design of the models.

    How is this supposed to be done generally? Or do most developers shove the data directly in the model and interface directly with it when making updates. This seems very limiting and quite odd to me, but maybe I haven't wrapped my head around the idea.

    Thanks in advance.
    Nick

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Well owning or not depend on your use case.

      That said, in your case, it seems that the model will be a wrapper on top of your data. In that case, there's a need to implement the model functions to forward the manipulations to your data structure (for example new rows insertions, removal, drag and drop, etc).

      You should also add adequate APIs that allows external changes to the data structure to be propagate through the model (for example when some data is changed).

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

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