QTableview appending data is slow



  • I have mdi sub sub window, I can able to create multiple instance for the mdi sub window. Inside sub window I have QTableview, I am continuously appending data to the QTableview. If I open 4 or more than 4 sub windows and keep on appending data to all the windows, my application and data appending to the tableview is very slow. Please help me to solve this problem.
    Thanks in advance.


  • Moderators

    @anandvivek said:

    Please help me to solve this problem.

    how should that be possible by these few lines of written text which basically just say no more than "i have a problem. help me"
    When the appending is slow by your opinion, then show the code of it or at least describe what you are doing in detail...



  • Whenever I am going to create sub window, I am creating object for the sub window.
    EzSubWindow *busDirectSubWindow;
    busDirectSubWindow = new EzBusDirectSubWindow(spaDocument, fileName,this);

    Inside this class I have connect signal to table model. I'm using tableview and setWidget(tableview) to busdirectsubwindow class.

    connect(this, SIGNAL(canFramesReceived(QVector<QStringList>)), _tableModel,SLOT(append(QVector<QStringList>)));
    

    If I'm getting data from device I will add the data to QVector<QstringList> variable and emit as a signal to the table model append slot.

    void EzTableModel::append(QVector<QStringList> data)
    {
    int removeRowCount = 0;
    int newRowCount = _rowCount + data.size();

    if (newRowCount > _maxRowCount) {
    removeRowCount = newRowCount - _maxRowCount;

    beginRemoveRows(QModelIndex(), 0, removeRowCount - 1);
    _data.remove(0, removeRowCount);
    newRowCount -= removeRowCount;
    endRemoveRows();
    

    }

    beginInsertRows(QModelIndex(), _rowCount - removeRowCount, newRowCount - 1);
    _data += data;
    _rowCount = newRowCount;
    endInsertRows();
    }

    This whole thing will happen for every sub window creation and reading data from device also separate for every window.
    This is my scenario. If I open multiple windows and run all the windows data appending and displaying data is getting slow.


  • Moderators

    @anandvivek
    first of all it should never possible that in your append() method the row count may decrease?!

    This should be enough:

    void EzTableModel::append(const QVector<QStringList> & appendData)
    {
    int count = _data.size();
    beginInsertRows(QModelIndex(), count, count + appendData.size() - 1);
    _data += appendData;
    endInsertRows();
    }
    

    But your problem is probably somewhere else.



  • Thanks for your suggestion. I will try to find the problem from where it is coming.


  • Moderators

    @anandvivek
    try removing small parts of your application step by step as good as possible to pin down the issue.



  • Sure. Thanks .


Log in to reply
 

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