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

    Christian EhrlicherC 1 Reply Last reply
    0
    • T tiegert

      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.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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
      2
      • Christian EhrlicherC Christian Ehrlicher

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

        Christian EhrlicherC 1 Reply Last reply
        0
        • T tiegert

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

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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

          • Login

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