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. Update multiple models based on an update of data
QtWS25 Last Chance

Update multiple models based on an update of data

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 907 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.
  • D Offline
    D Offline
    deleted560
    wrote on last edited by deleted560
    #1

    Re: Model/View: how to make external changes to models trigger updates in all views?

    I've been reading this thread and I was wondering exactly the same thing. The last post is approximately my question (from @SGaist):

    Are you expecting QSqlTableModel to automatically get notified by the database server that it has been changed by some external process and thus trigger a refresh ?

    Actually I'm not expecting that this happens magically, but I was wondering what it would take to have raw data updated somewhere that triggers multiple models updates and thus multiple views updates. How would the mapping between the data and the multiple models work ?

    For example:

    • I have a list of multiple Measurements which contain attributes like size, color and weight
    • One model is used as an interface with a QListView that displays only the size of all the Measurements
    • One model is used as an interface with a QTableView that displays the size and the color of all the Measurements
    • etc.

    Then I trigger an update on my raw data. How to prepend this change to all my associated models ?

    JonBJ 1 Reply Last reply
    0
    • D deleted560

      Re: Model/View: how to make external changes to models trigger updates in all views?

      I've been reading this thread and I was wondering exactly the same thing. The last post is approximately my question (from @SGaist):

      Are you expecting QSqlTableModel to automatically get notified by the database server that it has been changed by some external process and thus trigger a refresh ?

      Actually I'm not expecting that this happens magically, but I was wondering what it would take to have raw data updated somewhere that triggers multiple models updates and thus multiple views updates. How would the mapping between the data and the multiple models work ?

      For example:

      • I have a list of multiple Measurements which contain attributes like size, color and weight
      • One model is used as an interface with a QListView that displays only the size of all the Measurements
      • One model is used as an interface with a QTableView that displays the size and the color of all the Measurements
      • etc.

      Then I trigger an update on my raw data. How to prepend this change to all my associated models ?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Leogout
      Trying to put this all together for you....

      Forget about the views. They will update automatically if & when your models get updated.

      Then I trigger an update on my raw data.

      What do you mean by this/how does it happen? In the other post the question was about an external change being made in the database side, and how that could be detected. Here you talk about you doing some kind of update? If you are updating data in the database within your program, you could re-read the new data into your model(s). If the update happens quite outside your ken, then you are looking for notifications from the database to your program that changes have been made, and I think we have previously looked into this and the database drivers used in Qt do not support this, though you should specify what your database is.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deleted560
        wrote on last edited by deleted560
        #3

        Thanks for your answer. I think I mislead you by mentionning the previous post. I don't have a database, I have my own data source, which is a class containing some data. If I take my previous example back, lets say I have a MeasurementsData class which contais a list of Measurements.
        I would like to base my models on this data source and prepend the changes I make to this source to the other models, either by having one of my model update it directly or by something else, like an action triggered by a button pressed.

        JonBJ 1 Reply Last reply
        0
        • D deleted560

          Thanks for your answer. I think I mislead you by mentionning the previous post. I don't have a database, I have my own data source, which is a class containing some data. If I take my previous example back, lets say I have a MeasurementsData class which contais a list of Measurements.
          I would like to base my models on this data source and prepend the changes I make to this source to the other models, either by having one of my model update it directly or by something else, like an action triggered by a button pressed.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Leogout
          Then I don't think your question is connected to the other post you reference.

          I'm sorry, but not I'm as good at guessing what questioners want as some other people here! So I don't really understand your problem. If you have multiple models, and somehow changes in one should cause changes in others, then just write the necessary code to do so. Either directly (code goes "update model1; update model2;"), or if you prefer by attaching a signal on update in model1 to a slot which updates model2. I don't know what relevance "triggered by a button pressed" has, it doesn't matter how the update to model1 is performed.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted560
            wrote on last edited by
            #5

            Thanks for your time, I've posted this question on Stackoverflow as well and the answer is satisfying to me. Here it is:

            I'd consider to implement a single QAbstractListModel to provide all the data (via roles), and then use simple proxy models (QIdentityProxyModel subclasses) to map that data to the columns/roles (mainly Qt::DisplayRole) as needed for respective views.

            https://stackoverflow.com/questions/63049172/update-multiple-qt-models-based-on-a-single-data-source

            This is what I was looking for, a simple and automatic way to trigger updates based on a single source of truth. I'm not comfortable with the way you would handle the problem as your solution implies that multiple models have to know and connect to each other and the data source have to know them as well and trigger manual updates.

            Thanks for your time and no worries for the guessing part, I may have not been clear on what I wanted to achieve in the first place.

            Have a nice day.

            JonBJ 1 Reply Last reply
            0
            • D deleted560

              Thanks for your time, I've posted this question on Stackoverflow as well and the answer is satisfying to me. Here it is:

              I'd consider to implement a single QAbstractListModel to provide all the data (via roles), and then use simple proxy models (QIdentityProxyModel subclasses) to map that data to the columns/roles (mainly Qt::DisplayRole) as needed for respective views.

              https://stackoverflow.com/questions/63049172/update-multiple-qt-models-based-on-a-single-data-source

              This is what I was looking for, a simple and automatic way to trigger updates based on a single source of truth. I'm not comfortable with the way you would handle the problem as your solution implies that multiple models have to know and connect to each other and the data source have to know them as well and trigger manual updates.

              Thanks for your time and no worries for the guessing part, I may have not been clear on what I wanted to achieve in the first place.

              Have a nice day.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Leogout
              That's fine. I had no idea from your "multiple models updates" that your models had anything in common with one another to allow proxy models to be imposed on a single model to implement this. Evidently other people have better correct guessing/interpretation than I! :)

              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