Qt获取本地计算的CPU温度
1.windows系统
#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系统上
后续实践完成了 补上。