[Solved] QAbstractTableModel & QtableView querries?

  • Hi,
    In my application I have allocated 2D array which stores double variables. I want to display this in the form of a spreadsheet. So I am creating a custom model by subclassing QAbstractTableModel & setting it as the model for a QTableView. I have some querries:

    • The table view can only be in the GUI thread. But is it possible to put the table model in a different thread? If yes, would there be any specific advantage of doing this?
    • How does the table view know what data has to be displayed? I believe it uses rowCount() & columnCount() to know the dimensions of the table. Using this information it loops to determine value for each cell using data(). Is there anything else that I may have missed?
    • In the table model I am storing : int size & double **array as class variables. I am updating these variables from another class. Now suppose it was containing data of size 10x10 & view was displaying this. Now I want to change the data to a 20x20 size array. After updating the class variables how should I notify the table model & table view that the data has changed?
    • What does the dataChanged() SIGNAL do? Does it do anything to the table model also or just refreshes the table view?
    • Do I have to use createIndex()? If yes then when?

  • Expecting some helpful answers people...
    I am stuck up in my project...

    1. Yes, possibly. No, probably not.
    2. A combination of the signals from the model, e.g. dataChanged(), rowsAboutToBeInserted(), rowsInserted() etc.
    3. beginInsertRows(), endInsertRows() etc. It is all in the model view overview documentation in Assistant.
    4. It informs any attached views (note plural) that the data for the specified index has changed in some way. The view should update itself as appropriate.
    5. No, the base implementation is quite likely adequate.


  • Hi Chris,
    Thanks for your answer!
    Works like a charm.
    The documentation somehow I feel is a bit weak on this topic.
    I thought ..Insert..() are required only for inserting row/column in an existing table, similar to what can be done in Excel. The documentation does not say that I have to create the table using these functions.
    Anyways got it now!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.