How to update QAbstractTableModel data
Unsolved
General and Desktop
-
for (int k = 0; k < this->m_pKineticsInfo->GetTimes().count(); k++) { int nIndex = 0; for (int i = abs(m_pDataModel->columnCount() - m_pKineticsInfo->GetCellCount()); i < m_pDataModel->columnCount(); i++) { QList<qreal> temp; qreal qRan1 = QRandomGenerator::global()->bounded(0, 10); qreal qRan2 = QRandomGenerator::global()->generateDouble(); temp.append(qRan1 + qRan2); m_pDataModel->AppendData(temp, i); lstSummary[nIndex++].AppendData(qRan1 + qRan2, this->m_pKineticsInfo->GetTimes()[k], m_pKineticsInfo->StringtoEnumUnit()); } AddChartSeries(m_pDataModel); } void usrTableModel::AppendData(QList<qreal> data, int nIndex) { auto EmptyIndex = [=]()->int { for (int i = 0; i < m_lstData.count(); i++) { if (m_lstData[i].second.count() == 0) return i; } }; m_lstData[nIndex].second.append(data); // [데이터 index 재 할당] QModelIndex index = createIndex(m_lstData.at(0).second.count(), m_lstData.count()); emit dataChanged(index, index); emit UserDefineAppendData(); }
When data is updated in a class that inherits QAbstractTableModel, the update is not immediately reflected on the UI.
It is updated when you move the mouse over the table or when you put the table back on the focus somewhere else.
How do I update a table?
-
@IknowQT
It certainly should update without needing a refresh.At a guess from your code: you
emit dataChanged()
, which is what is required if you alter existing data in a table. However I see a lot ofappend
ing going on. If you are adding/appending/inserting new rows of data rather than just altering existing ones you must useinsertRows()
and callbegin
/endInsertRows()
from it, all as per the Subclassing topic. Have you read that, isn't that related to whatever your code does?