How to save data in memory to use ?
Solved
General and Desktop
-
I am writing a process manager, I need to save data to calculate [procCpuTime - procCpuTime0] and else by pid.
void MainWindow::update() { QDir dir("/proc"); QFileInfoList FIL; FIL = dir.entryInfoList(); for (int i = 0; i < FIL.size(); i++) { if (FIL.at(i).isDir()) { QString spid = FIL.at(i).fileName(); QFile file; file.setFileName("/proc/" + spid + "/stat"); file.open(QIODevice::ReadOnly); s = file.readLine(); file.close(); SL = s.split(" "); long utime = SL.at(13).toLong(); long stime = SL.at(14).toLong(); long cutime = SL.at(15).toLong(); long cstime = SL.at(16).toLong(); long procCpuTime = utime + stime + cutime + cstime; int uProc = 100 * (procCpuTime - procCpuTime0) / (totalCpuTime - totalCpuTime0); QTableWidgetItem *TWI = new QTableWidgetItem(QString::number(uProc) + "%"); TWI->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); ui->tableWidget->setItem(j, 2, TWI); } } procCpuTime0 = procCpuTime; }
-
I am writing a process manager, I need to save data to calculate [procCpuTime - procCpuTime0] and else by pid.
void MainWindow::update() { QDir dir("/proc"); QFileInfoList FIL; FIL = dir.entryInfoList(); for (int i = 0; i < FIL.size(); i++) { if (FIL.at(i).isDir()) { QString spid = FIL.at(i).fileName(); QFile file; file.setFileName("/proc/" + spid + "/stat"); file.open(QIODevice::ReadOnly); s = file.readLine(); file.close(); SL = s.split(" "); long utime = SL.at(13).toLong(); long stime = SL.at(14).toLong(); long cutime = SL.at(15).toLong(); long cstime = SL.at(16).toLong(); long procCpuTime = utime + stime + cutime + cstime; int uProc = 100 * (procCpuTime - procCpuTime0) / (totalCpuTime - totalCpuTime0); QTableWidgetItem *TWI = new QTableWidgetItem(QString::number(uProc) + "%"); TWI->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); ui->tableWidget->setItem(j, 2, TWI); } } procCpuTime0 = procCpuTime; }
-
The model is the place where you save the data already just store it in different roles:
QTableWidgetItem *TWI = new QTableWidgetItem; TWI->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); TWI->setData(Qt::EditRole,uProc); TWI->setData(Qt::UserRole,procCpuTime0); TWI->setData(Qt::UserRole+1,procCpuTime ); TWI->setData(Qt::UserRole+2,totalCpuTime0); TWI->setData(Qt::UserRole+3,totalCpuTime );
-
I am writing a process manager, I need to save data to calculate [procCpuTime - procCpuTime0] and else by pid.
void MainWindow::update() { QDir dir("/proc"); QFileInfoList FIL; FIL = dir.entryInfoList(); for (int i = 0; i < FIL.size(); i++) { if (FIL.at(i).isDir()) { QString spid = FIL.at(i).fileName(); QFile file; file.setFileName("/proc/" + spid + "/stat"); file.open(QIODevice::ReadOnly); s = file.readLine(); file.close(); SL = s.split(" "); long utime = SL.at(13).toLong(); long stime = SL.at(14).toLong(); long cutime = SL.at(15).toLong(); long cstime = SL.at(16).toLong(); long procCpuTime = utime + stime + cutime + cstime; int uProc = 100 * (procCpuTime - procCpuTime0) / (totalCpuTime - totalCpuTime0); QTableWidgetItem *TWI = new QTableWidgetItem(QString::number(uProc) + "%"); TWI->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); ui->tableWidget->setItem(j, 2, TWI); } } procCpuTime0 = procCpuTime; }