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系统上

后续实践完成了 补上。

相关推荐
Littlehero_12112 小时前
QT自定义控件之内嵌报表(4)(源码开源)
开发语言·qt
lqj_本人17 小时前
鸿蒙跨端实战_QT后台切换导致OpenGLES上下文丢失:黑屏自救指南
qt·华为·harmonyos
小小龙学IT18 小时前
第七节 C++ 与 QML 交互
开发语言·qt
qq_4017004119 小时前
TCP 粘包问题深度解析:嵌入式网络开发的常见坑与解决方案
服务器·网络·qt·网络协议·tcp/ip
ShineWinsu19 小时前
对于TRAE中配置Qt的解析
开发语言·c++·ide·vscode·qt·ai·trae
小小龙学IT20 小时前
第一节 QML 背景介绍
c++·qt·js
此陆昭昭20 小时前
qt,使用qml写一个简单的界面
c++·qt
丰锋ff21 小时前
基于 Qt 的智能门禁系统(三)
开发语言·qt
wind100321 天前
Qt5Widgets.dll 缺失报错|游戏软件无法启动完整修复教程
开发语言·qt·游戏·电脑
丰锋ff1 天前
基于 Qt 的智能门禁系统(二)
开发语言·qt