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. Model/View and Custom Data Models - Data in the backend
QtWS25 Last Chance

Model/View and Custom Data Models - Data in the backend

Scheduled Pinned Locked Moved Unsolved General and Desktop
modelviewcustom modelqabstractmodel
4 Posts 2 Posters 480 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.
  • T Offline
    T Offline
    tiegert
    wrote on 13 Oct 2023, 14:17 last edited by
    #1

    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.

    C 1 Reply Last reply 13 Oct 2023, 14:38
    0
    • T tiegert
      13 Oct 2023, 14:17

      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.

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 13 Oct 2023, 14:38 last edited by
      #2

      @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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      T 1 Reply Last reply 14 Oct 2023, 06:12
      2
      • C Christian Ehrlicher
        13 Oct 2023, 14:38

        @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.

        T Offline
        T Offline
        tiegert
        wrote on 14 Oct 2023, 06:12 last edited by
        #3

        @Christian-Ehrlicher
        So the correct way of working on the data it is, to only access the data through the model. Thanks

        C 1 Reply Last reply 14 Oct 2023, 06:27
        0
        • T tiegert
          14 Oct 2023, 06:12

          @Christian-Ehrlicher
          So the correct way of working on the data it is, to only access the data through the model. Thanks

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 14 Oct 2023, 06:27 last edited by
          #4

          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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1

          1/4

          13 Oct 2023, 14:17

          • 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