Important: Please read the Qt Code of Conduct -

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

  • 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:
    (empty the model, set rowCount() to 0)
    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.


  • Lifetime Qt Champion


    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 ?

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

  • Lifetime Qt Champion

    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.

  • @SGaist

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

  • 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
    That mailing list is visited by most Qt developers regularly.


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

Log in to reply