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. 2 QTableView with 1 model... do they work?
Forum Update on Monday, May 27th 2025

2 QTableView with 1 model... do they work?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.1k 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.
  • F Offline
    F Offline
    fp615
    wrote on last edited by
    #1

    Is it possible to have a form with 2 QTableView that use the same model? I saw examples using 1 model on different Q*View widgets.

    I ask this question since I get a strange behaviour.

    I create a form, QTableView grid01, setModel to grid01; create QTableView grid02, setModel to grid02.

    Both grids show correct data.

    Then I need to update (filter) the data in the grids, so I do:
    model:beginResetModel()
    (empty the model, set rowCount() to 0)
    model:endResetModel()
    and load data, row by row, with a couple of beginInsertRows( QModelIndex(), nRow, nRow ), endInsertRows.

    What I get is that grid02 has been correctly updated: the scrollbar, for example, scrolls correctly and the correct number of rows is requested by :data().

    grid01, instead, has not been updated in the number of rows it can display: the scrollbar range has not been updated so I get :data() requests for rows that doesn't exist...

    Unfortunately I'm using a language you probably never heard of and it is difficult for me to test in a pure c++ setup, so I ask you: have you ever used 2 QTableView with 1 model in the same form?

    If you did, there is something that is preventing grid01 from receiving the signals about rows change.

    Thanks

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

      Hi,

      From your description your using two different models with two different views so it probably make sense that view1 is not updated when you change the content for grid02.

      What mysterious language is it that you use ?

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

      F 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        From your description your using two different models with two different views so it probably make sense that view1 is not updated when you change the content for grid02.

        What mysterious language is it that you use ?

        F Offline
        F Offline
        fp615
        wrote on last edited by
        #3

        @SGaist

        Thanks for your answer. Unfortunately the model is the same, infact after the reset in grid01 I get the new data for the rows the model now has - for all the others I return a "n.a." string...

        So, the model is definitively one, it just seems that grid01 QTableView doesn't receive the signals and so it can't update its internal state.

        The language I'm using is called Harbour, and it is a modern, multiplatform (windows, linux, mac, android, os/2, everywhere there is a c compiler), state of the art, open-source version of Clipper, a compiler of the dBaseIII+ database... we are talking about 1984...

        We wrote a layer to use Qt with Harbour. I already dug into different source code files to follow internal logic but could not find where the problem is. So I'm asking if this setup work correctly in c++, since it will take too much time for me to create a working sample in c++.

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

          It should work yes. You have the Item View Chart example that demonstrates that you can have two radically different views on the same model.

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

          F 1 Reply Last reply
          0
          • SGaistS SGaist

            It should work yes. You have the Item View Chart example that demonstrates that you can have two radically different views on the same model.

            F Offline
            F Offline
            fp615
            wrote on last edited by
            #5

            @SGaist

            Unfortunately I need to test with 2 radically EQUAL views :-)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alex_malyu
              wrote on last edited by
              #6

              There is no any difference if views are equal or different.
              It works if model is properly implemented.
              I have cases using both Qt4 and Qt 5.

              Problem might be related to language binding and is mostly likely out of scope for this forum.
              You may have more luck to get an advice at interest@qt-project.org.
              That mailing list is visited by most Qt developers regularly.

              Regards

              F 1 Reply Last reply
              0
              • A alex_malyu

                There is no any difference if views are equal or different.
                It works if model is properly implemented.
                I have cases using both Qt4 and Qt 5.

                Problem might be related to language binding and is mostly likely out of scope for this forum.
                You may have more luck to get an advice at interest@qt-project.org.
                That mailing list is visited by most Qt developers regularly.

                Regards

                F Offline
                F Offline
                fp615
                wrote on last edited by
                #7

                @alex_malyu
                This form was coded exactly for that reason: testing a model I was writing. And I found a flaw in it. I didn't test if the new, correct, version, shows this problem again, but I solved others ((I was using threads to update the model) in the meantime.

                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