Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to save data in memory to use ?
QtWS25 Last Chance

How to save data in memory to use ?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 418 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    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;
    }
    

    替代文字

    https://github.com/sonichy

    jsulmJ sonichyS 2 Replies Last reply
    0
    • sonichyS sonichy

      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;
      }
      

      替代文字

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sonichy QMap or QHash with pid as key...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        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 );
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        4
        • sonichyS sonichy

          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;
          }
          

          替代文字

          sonichyS Offline
          sonichyS Offline
          sonichy
          wrote on last edited by
          #4

          @sonichy Use QList<QStringList> to save data right now.

          https://github.com/sonichy

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved