1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      Qt如何實現(xiàn)硬盤容量控件

      小編給大家分享一下Qt如何實現(xiàn)硬盤容量控件,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

      成都創(chuàng)新互聯(lián)公司一直通過網(wǎng)站建設(shè)和網(wǎng)站營銷幫助企業(yè)獲得更多客戶資源。 以"深度挖掘,量身打造,注重實效"的一站式服務(wù),以網(wǎng)站建設(shè)、做網(wǎng)站、移動互聯(lián)產(chǎn)品、營銷型網(wǎng)站建設(shè)服務(wù)為核心業(yè)務(wù)。十多年網(wǎng)站制作的經(jīng)驗,使用新網(wǎng)站建設(shè)技術(shù),全新開發(fā)出的標準網(wǎng)站,不但價格便宜而且實用、靈活,特別適合中小公司網(wǎng)站制作。網(wǎng)站管理系統(tǒng)簡單易用,維護方便,您可以完全操作網(wǎng)站資料,是中小公司快速網(wǎng)站建設(shè)的選擇。

      一、前言

      磁盤容量統(tǒng)計控件,說白了,就是用來統(tǒng)計本地盤符占用的容量,包括但不限于已用空間、剩余空間、總大小、已用百分比等,其中對應(yīng)的百分比采用進度條顯示,該進度條的前景色和背景色及文字顏色可以設(shè)置,在整體換膚的時候就需要用到。 本控件的基本上沒有難點可言,就是兼容WIN和LINUX操作系統(tǒng),在WIN上采用winapi去讀取,linux采用QProcess去執(zhí)行對應(yīng)的命令(df -h)獲取結(jié)果,然后定時器執(zhí)行,關(guān)聯(lián)信號槽獲取返回的額數(shù)據(jù)解析即可,控件的應(yīng)用場景主要是在一些嵌入式設(shè)備上面,方便用戶查看當前還剩余多少空間。

      主要功能:

      1. 可自動加載本地存儲設(shè)備的總?cè)萘?已用容量

      2. 進度條顯示已用容量

      3. 支持所有操作系統(tǒng)

      4. 增加U盤或者SD卡到達信號

      二、代碼思路

      void DeviceSizeTable::load()
      {
          //清空原有數(shù)據(jù)
          int row = this->rowCount();
          for (int i = 0; i < row; i++) {
              this->removeRow(0);
          }
      
      #ifdef Q_OS_WIN
          QFileInfoList list = QDir::drives();
          foreach (QFileInfo dir, list) {
              QString dirName = dir.absolutePath();
              LPCWSTR lpcwstrDriver = (LPCWSTR)dirName.utf16();
              ULARGE_INTEGER liFreeBytesAvailable, liTotalBytes, liTotalFreeBytes;
      
              if (GetDiskFreeSpaceEx(lpcwstrDriver, &liFreeBytesAvailable, &liTotalBytes, &liTotalFreeBytes)) {
                  QString use = QString::number((double)(liTotalBytes.QuadPart - liTotalFreeBytes.QuadPart) / GB, 'f', 1);
                  use += "G";
                  QString free = QString::number((double) liTotalFreeBytes.QuadPart / GB, 'f', 1);
                  free += "G";
                  QString all = QString::number((double) liTotalBytes.QuadPart / GB, 'f', 1);
                  all += "G";
                  int percent = 100 - ((double)liTotalFreeBytes.QuadPart / liTotalBytes.QuadPart) * 100;
                  insertSize(dirName, use, free, all, percent);
              }
          }
      
      #else
          process->start("df -h");
      #endif
      }
      
      void DeviceSizeTable::readData()
      {
          while (!process->atEnd()) {
              QString result = QLatin1String(process->readLine());
      #ifdef __arm__
              if (result.startsWith("/dev/root")) {
                  checkSize(result, "本地存儲");
              } else if (result.startsWith("/dev/mmcblk")) {
                  checkSize(result, "本地存儲");
              } else if (result.startsWith("/dev/mmcblk1p")) {
                  checkSize(result, "SD卡");
                  QStringList list = result.split(" ");
                  emit sdcardReceive(list.at(0));
              } else if (result.startsWith("/dev/sd")) {
                  checkSize(result, "U盤");
                  QStringList list = result.split(" ");
                  emit udiskReceive(list.at(0));
              }
      #else
              if (result.startsWith("/dev/sd")) {
                  checkSize(result, "");
                  QStringList list = result.split(" ");
                  emit udiskReceive(list.at(0));
              }
      #endif
          }
      }
      
      void DeviceSizeTable::checkSize(const QString &result, const QString &name)
      {
          QString dev, use, free, all;
          int percent = 0;
          QStringList list = result.split(" ");
          int index = 0;
      
          for (int i = 0; i < list.count(); i++) {
              QString s = list.at(i).trimmed();
              if (s == "") {
                  continue;
              }
      
              index++;
              if (index == 1) {
                  dev = s;
              } else if (index == 2) {
                  all = s;
              } else if (index == 3) {
                  use = s;
              } else if (index == 4) {
                  free = s;
              } else if (index == 5) {
                  percent = s.left(s.length() - 1).toInt();
                  break;
              }
          }
      
          if (name.length() > 0) {
              dev = name;
          }
      
          insertSize(dev, use, free, all, percent);
      }
      
      void DeviceSizeTable::insertSize(const QString &name, const QString &use, const QString &free, const QString &all, int percent)
      {
          int row = this->rowCount();
          this->insertRow(row);
      
          QTableWidgetItem *itemname = new QTableWidgetItem(name);
          QTableWidgetItem *itemuse = new QTableWidgetItem(use);
          itemuse->setTextAlignment(Qt::AlignCenter);
          QTableWidgetItem *itemfree = new QTableWidgetItem(free);
          itemfree->setTextAlignment(Qt::AlignCenter);
          QTableWidgetItem *itemall = new QTableWidgetItem(all);
          itemall->setTextAlignment(Qt::AlignCenter);
      
          this->setItem(row, 0, itemname);
          this->setItem(row, 1, itemuse);
          this->setItem(row, 2, itemfree);
          this->setItem(row, 3, itemall);
      
          QProgressBar *bar = new QProgressBar;
          bar->setRange(0, 100);
          bar->setValue(percent);
      
          QString qss = QString("QProgressBar{background:%1;border-width:0px;border-radius:0px;text-align:center;}"
                                "QProgressBar::chunk{border-radius:0px;}").arg(bgColor.name());
      
          if (percent < 50) {
              qss += QString("QProgressBar{color:%1;}QProgressBar::chunk{background:%2;}").arg(textColor1.name()).arg(chunkColor1.name());
          } else if (percent < 90) {
              qss += QString("QProgressBar{color:%1;}QProgressBar::chunk{background:%2;}").arg(textColor2.name()).arg(chunkColor2.name());
          } else {
              qss += QString("QProgressBar{color:%1;}QProgressBar::chunk{background:%2;}").arg(textColor3.name()).arg(chunkColor3.name());
          }
      
          bar->setStyleSheet(qss);
          this->setCellWidget(row, 4, bar);
      }

      三、效果圖

      Qt如何實現(xiàn)硬盤容量控件

      以上是“Qt如何實現(xiàn)硬盤容量控件”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!


      當前標題:Qt如何實現(xiàn)硬盤容量控件
      瀏覽地址:http://www.ef60e0e.cn/article/jhpegd.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        紫金县| 绥宁县| 齐齐哈尔市| 军事| 禄丰县| 衡阳市| 永安市| 锦屏县| 杭锦旗| 安阳市| 大关县| 灵寿县| 石城县| 左云县| 博湖县| 衡东县| 藁城市| 朝阳市| 惠东县| 武夷山市| 阿拉善右旗| 永嘉县| 祁东县| 濉溪县| 龙游县| 海阳市| 龙游县| 兰坪| 清丰县| 双鸭山市| 定南县| 军事| 阿尔山市| 临猗县| 宜都市| 卓资县| 光泽县| 嘉义县| 白沙| 车险| 屏边|