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

后续实践完成了 补上。

相关推荐
Quz9 小时前
QML Hello World 入门示例
qt
xcyxiner3 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner4 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner4 天前
DicomViewer (添加模型类)3
qt
xcyxiner5 天前
DicomViewer (目录调整) 2
qt
xcyxiner5 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能7 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G7 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt
森G7 天前
77、线程池原理和实现------服务器源码解析----云视频服务项目
服务器·c++·qt
森G7 天前
71、打包发布---------打包发布
c++·qt