当前位置: 首页 > news >正文

濮阳免费网站制作维修网站建设

濮阳免费网站制作,维修网站建设,上海装修设计公司,大连软件培训一、前言 在很多软件上#xff0c;会在某个部位显示一个部件#xff0c;专门显示当前的CPU使用率以及内存占用#xff0c;方便用户判断当前程序或者当前环境中是否还有剩余的CPU和内存留给程序使用#xff0c;在不用打开任务管理器或者资源查看器的时候直接得知当前系统的…一、前言 在很多软件上会在某个部位显示一个部件专门显示当前的CPU使用率以及内存占用方便用户判断当前程序或者当前环境中是否还有剩余的CPU和内存留给程序使用在不用打开任务管理器或者资源查看器的时候直接得知当前系统的运行情况。尤其是视频监控系统如果64路全开肯定很占用CPU和内存情况这样直接在软件上直观的查看到当前占用率用户更方便判断当前电脑环境是否适合打开多少路通道。 采集本地系统的实时CPU使用率如果使用的GetSystemTimes函数会发现和本地任务管理器中的不一致主要集中在win10系统/win7和XP系统貌似正常那是因为计数统计的方式不一样采用GetSystemTimes函数获取到的值相对来说是系统底层的数据。为了能够和任务管理器中展示的一致试验过各种办法后决定采用命令行获取的形式处理这样获取到的值是一致的在win10以下的系统执行 typeperf “\Processor(_Total)\% Processor Time”在win10及以上的系统执行 typeperf “\Processor Information(_Total)\% Processor Utility”。执行命令采用QProcess类执行结果有信号通知直接读取解析即可。同理在linux系统上也是采用执行命令行的形式获取比如linux上获取CPU占用命令是 cat /proc/stat获取内存相关命令是 cat /proc/meminfo。在windows上获取内存相关使用函数 GlobalMemoryStatusEx。 二、主要功能 实时显示当前CPU占用率。实时显示内存使用情况。包括共多少内存、已使用多少内存。全平台通用包括windows、linux、ARM。发出信号通知占用率和内存使用情况等以便自行显示到其他地方。 三、效果图 四、开源主页 以上作品完整源码下载都在开源主页会持续不断更新作品数量和质量欢迎各位关注。本开源项目已经成功升级到V2.0版本分门别类图文并茂保你爽到爆。Qt开源武林秘籍开发经验看完学完20K起薪没有找我 国内站点https://gitee.com/feiyangqingyun/QWidgetDemo国际站点https://github.com/feiyangqingyun/QWidgetDemo开源秘籍https://gitee.com/feiyangqingyun/qtkaifajingyan个人主页https://qtchina.blog.csdn.net/视频主页https://space.bilibili.com/687803542 五、核心代码 #pragma execution_character_set(utf-8)#include cpumemorylabel.h #include qtimer.h #include qprocess.h #include qdebug.h#ifdef Q_OS_WIN #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x502 #endif #include windows.h #endif#define MB (1024 * 1024) #define KB (1024)CpuMemoryLabel::CpuMemoryLabel(QWidget *parent) : QLabel(parent) {totalNew idleNew totalOld idleOld 0;cpuPercent 0;memoryPercent 0;memoryAll 0;memoryUse 0;//获取CPU占用情况定时器timerCPU new QTimer(this);connect(timerCPU, SIGNAL(timeout()), this, SLOT(getCPU()));//获取内存占用情况定时器timerMemory new QTimer(this);connect(timerMemory, SIGNAL(timeout()), this, SLOT(getMemory()));//执行命令获取process new QProcess(this);connect(process, SIGNAL(readyRead()), this, SLOT(readData()));showText true; }CpuMemoryLabel::~CpuMemoryLabel() {this-stop(); }void CpuMemoryLabel::start(int interval) {this-getCPU();this-getMemory();if (!timerCPU-isActive()) {timerCPU-start(interval);}if (!timerMemory-isActive()) {timerMemory-start(interval 1000);} }void CpuMemoryLabel::stop() {process-close();if (timerCPU-isActive()) {timerCPU-stop();}if (timerMemory-isActive()) {timerMemory-stop();} }void CpuMemoryLabel::getCPU() { #ifdef Q_OS_WIN #if 0static FILETIME lastIdleTime;static FILETIME lastKernelTime;static FILETIME lastUserTime;FILETIME newIdleTime;FILETIME newKernelTime;FILETIME newUserTime;//采用GetSystemTimes获取的CPU占用和任务管理器的不一致GetSystemTimes(newIdleTime, newKernelTime, newUserTime);int offset 31;quint64 a, b;quint64 idle, kernel, user;a (lastIdleTime.dwHighDateTime offset) | lastIdleTime.dwLowDateTime;b (newIdleTime.dwHighDateTime offset) | newIdleTime.dwLowDateTime;idle b - a;a (lastKernelTime.dwHighDateTime offset) | lastKernelTime.dwLowDateTime;b (newKernelTime.dwHighDateTime offset) | newKernelTime.dwLowDateTime;kernel b - a;a (lastUserTime.dwHighDateTime offset) | lastUserTime.dwLowDateTime;b (newUserTime.dwHighDateTime offset) | newUserTime.dwLowDateTime;user b - a;cpuPercent float(kernel user - idle) * 100 / float(kernel user);lastIdleTime newIdleTime;lastKernelTime newKernelTime;lastUserTime newUserTime;this-setData(); #else//获取系统版本区分win10bool win10 false; #if (QT_VERSION QT_VERSION_CHECK(5,4,0))win10 (QSysInfo::productVersion().mid(0, 2).toInt() 10); #elsewin10 (QSysInfo::WindowsVersion 192); #endifQString cmd \\Processor(_Total)\\% Processor Time;if (win10) {cmd \\Processor Information(_Total)\\% Processor Utility;}if (process-state() QProcess::NotRunning) {process-start(typeperf, QStringList() cmd);} #endif#elif defined(Q_OS_UNIX) !defined(Q_OS_WASM)if (process-state() QProcess::NotRunning) {totalNew idleNew 0;process-start(cat, QStringList() /proc/stat);} #endif }void CpuMemoryLabel::getMemory() { #ifdef Q_OS_WINMEMORYSTATUSEX statex;statex.dwLength sizeof(statex);GlobalMemoryStatusEx(statex);memoryPercent statex.dwMemoryLoad;memoryAll statex.ullTotalPhys / MB;memoryFree statex.ullAvailPhys / MB;memoryUse memoryAll - memoryFree;this-setData();#elif defined(Q_OS_UNIX) !defined(Q_OS_WASM)if (process-state() QProcess::NotRunning) {process-start(cat, QStringList() /proc/meminfo);} #endif }void CpuMemoryLabel::readData() { #ifdef Q_OS_WINwhile (!process-atEnd()) {QString s QLatin1String(process-readLine());s s.split(,).last();s.replace(\r, );s.replace(\n, );s.replace(\, );if (!s.isEmpty() s.length() 10) {cpuPercent qRound(s.toFloat());}} #elif defined(Q_OS_UNIX) !defined(Q_OS_WASM)while (!process-atEnd()) {QString s QLatin1String(process-readLine());if (s.startsWith(cpu)) {QStringList list s.split( );idleNew list.at(5).toUInt();foreach (QString value, list) {totalNew value.toUInt();}quint64 total totalNew - totalOld;quint64 idle idleNew - idleOld;cpuPercent 100 * (total - idle) / total;totalOld totalNew;idleOld idleNew;break;} else if (s.startsWith(MemTotal)) {s.replace( , );s s.split(:).at(1);memoryAll s.left(s.length() - 3).toUInt() / KB;} else if (s.startsWith(MemFree)) {s.replace( , );s s.split(:).at(1);memoryFree s.left(s.length() - 3).toUInt() / KB;} else if (s.startsWith(Buffers)) {s.replace( , );s s.split(:).at(1);memoryFree s.left(s.length() - 3).toUInt() / KB;} else if (s.startsWith(Cached)) {s.replace( , );s s.split(:).at(1);memoryFree s.left(s.length() - 3).toUInt() / KB;memoryUse memoryAll - memoryFree;memoryPercent 100 * memoryUse / memoryAll;break;}} #endifthis-setData(); }void CpuMemoryLabel::setData() {cpuPercent (cpuPercent 0 ? 0 : cpuPercent);cpuPercent (cpuPercent 100 ? 0 : cpuPercent);QString msg QString(CPU %1% Mem %2% ( 已用 %3 MB / 共 %4 MB )).arg(cpuPercent).arg(memoryPercent).arg(memoryUse).arg(memoryAll);if (showText) {this-setText(msg);}emit textChanged(msg);emit valueChanged(cpuPercent, memoryPercent, memoryAll, memoryUse, memoryFree); }QSize CpuMemoryLabel::sizeHint() const {return QSize(300, 30); }QSize CpuMemoryLabel::minimumSizeHint() const {return QSize(30, 10); }bool CpuMemoryLabel::getShowText() const {return this-showText; }void CpuMemoryLabel::setShowText(bool showText) {this-showText showText; }
http://www.dnsts.com.cn/news/262380.html

相关文章:

  • 服装网站建设项目实施报告范文网页设计跟做网站一样吗
  • 创建电子商务网站的步骤织梦网站建设流程
  • 网站 做购物车阳江问政平台官网入口
  • 对单位网站的要求怎么可以创建网站
  • 手机模板的网站哪个好哪个网站做调查赚钱多
  • 安卓app整站织梦网站源码触屏网站建设
  • 西南大学校园网站建设往年考试卷南京专业网站制作哪家好
  • 网站如何做触屏滑动做网站有好创意想法
  • wordpress建站服务器选择自适应网站用什么软件设计
  • 顺德网站定制设计手机如何制作图片
  • 网站建设得花多钱企业网站的宣传功能体现在().
  • 黄浦网站设计人教版优化设计电子书
  • 个人网站可以做哪些内容注册网站送金币
  • 怎么查询菠菜网站做没作弊百度电脑版网页
  • 网站建设 军报网站有哪些费用多少钱
  • 网站制作 温州服务器怎么运行网站
  • 网站开发小程序开发wordpress大量发文章
  • 龙口建网站首选公司网站什么做才会更吸引客户
  • 建设网官网首页什么网站做优化最好?
  • 做淘宝要用的网站吗上海移动端网络推广哪家强
  • 奎文区建设局网站网站制作怎么报价
  • 网站内页产品 首页推荐网站的网站建设企业
  • 帝国cms小说网站模板下载保定曲阳网站建设
  • 做淘客要有好的网站如何制作app图标
  • 网站建设的流程电子商务phpstorm做网站
  • 衡水哪里可以做网站哪里做网站的比较多
  • 网站建设的简历制作重庆是哪个省的城市
  • 网站怎么做下载功能广州网址大全
  • 怎样建设百度网站wordpress该目录之后404
  • 学习网站建设总结上海设计网站设计