Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved How to save data in memory to use ?

    General and Desktop
    3
    4
    194
    Loading More Posts
    • 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.
    • sonichy
      sonichy last edited by

      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

      jsulm sonichy 2 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @sonichy last edited by

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

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

        1 Reply Last reply Reply Quote 0
        • VRonin
          VRonin last edited by

          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 Reply Quote 4
          • sonichy
            sonichy @sonichy last edited by

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

            https://github.com/sonichy

            1 Reply Last reply Reply Quote 0
            • First post
              Last post