Qt获取本地计算的CPU温度

1.windows系统

cpp 复制代码
#include <QCoreApplication>
#include <QProcess>
#include <QDebug>

void getCpuTemperature()
{
    QProcess process;
    // PowerShell命令用于获取CPU温度
    QString program = "powershell.exe";
    QStringList arguments;
    arguments << "-Command"
              << "Get-CimInstance -Namespace root/WMI -ClassName MSAcpi_ThermalZoneTemperature | "
                 "Select-Object -First 1 | ForEach-Object {($_.CurrentTemperature - 2732) / 10}";

    process.start(program, arguments);
    process.waitForFinished();

    QByteArray output = process.readAllStandardOutput();
    QString temperatureStr = QString::fromUtf8(output.trimmed());

    qDebug() << "CPU Temperature:" << temperatureStr + " C";
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    getCpuTemperature();

    return a.exec();
}

2.linux系统上

后续实践完成了 补上。

相关推荐
mengzhi啊4 小时前
SerialPortItem对串口再封装一层,省去一些常用的步骤,不用每次都去写类
qt
用户83344239661416 小时前
从批量操作到任务中心,再到现场工作台:DeviceForge v2.10—v2.12 完整演进
qt
宛 禾18 小时前
Qt 控件入门:QLabel 从拖拽到对象树,一篇讲透
c++·qt·学习
打工仔折腾 AI1 天前
Qt网络编程实战:UDP、TCP到HTTP的落地经验与选型
网络·人工智能·后端·python·qt·udp·ai agent 实战
Lhan.zzZ1 天前
Linux + Qt/QML:解决 QtQuick.VirtualKeyboard.Plugins 模块加载失败与环境变量配置
linux·数据库·qt
誰能久伴不乏1 天前
QT工业上位机一次「指令静默丢失」的排查
qt·docker·github
扶尔魔ocy2 天前
【qt openGL入门笔记】OSG实现飞机模型在网格图上飞行并进行态势标绘(四)
qt·opengl·osg
橙橙笔记2 天前
QT安卓软件的制作
android·git·qt·软件
芦芭荞2 天前
QT使用xml模版生成word文档
xml·qt·word
mengzhi啊2 天前
qt把结构体数据存入json文件
qt·json