Since there is a lot of code, I'll take off a piece) I do the following. Wrote my model from QAbstractTableModel. Tied to QTableView. By timer (0.5 sec) I update the list of processes and put it in a table, while calculating the difference between the previous and updated list of processes and, in accordance with this difference, I add or delete rows in the table, and then rewrite the data. The problem is this: when displaying a table, the data does not change at all. However, if you select a row or scroll the table back and forth, then they are updated ... Some kind of problem with drawing something) How to fix this? Thanks in advance)
void ProcessMonitor::updateProcessList() { QDir *dir = new QDir("/proc"); QStringList dirProcessList = dir->entryList(QStringList("*"), QDir::AllDirs); QFile stat; int len = processList.size(); processList.clear(); foreach(QString str, dirProcessList) { if (str.toInt()) { stat.setFileName("/proc/" + str.toUtf8() + "/stat"); stat.open(QIODevice::ReadOnly); processList.append(getProcessInfoByStat(&stat)); stat.close(); } else continue; } int dif = len - processList.size(); if (dif < 0) { processTableModel->insertRows(0, -dif, QModelIndex()); } else if (dif > 0) { processTableModel->removeRows(0, dif, QModelIndex()); } for (int i = 0; i < processList.size(); i++) { processTableModel->setData(processTableModel->index(i, 0), processList.at(i)->comm, Qt::DisplayRole); processTableModel->setData(processTableModel->index(i, 1), processList.at(i)->pid, Qt::DisplayRole); processTableModel->setData(processTableModel->index(i, 2), processList.at(i)->stat, Qt::DisplayRole); processTableModel->setData(processTableModel->index(i, 3), processList.at(i)->nice, Qt::DisplayRole); processTableModel->setData(processTableModel->index(i, 4), processList.at(i)->cpu, Qt::DisplayRole); processTableModel->setData(processTableModel->index(i, 5), processList.at(i)->stime, Qt::DisplayRole); } sort(); }