deepin系统 qt编程如何获取显卡温度
时间: 2024-05-05 21:17:33 浏览: 220
您可以使用NVIDIA的NVML库来获取显卡温度,以下是获取显卡温度的代码示例:
```c++
#include <nvml.h>
#include <iostream>
int main()
{
nvmlReturn_t result;
nvmlDevice_t device;
unsigned int temperature;
// 初始化NVML库
result = nvmlInit();
if (result != NVML_SUCCESS) {
std::cerr << "Failed to initialize NVML: " << nvmlErrorString(result) << std::endl;
return -1;
}
// 获取第一个GPU设备
result = nvmlDeviceGetHandleByIndex(0, &device);
if (result != NVML_SUCCESS) {
std::cerr << "Failed to get device handle: " << nvmlErrorString(result) << std::endl;
nvmlShutdown();
return -1;
}
// 获取温度
result = nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &temperature);
if (result != NVML_SUCCESS) {
std::cerr << "Failed to get temperature: " << nvmlErrorString(result) << std::endl;
nvmlShutdown();
return -1;
}
std::cout << "GPU temperature: " << temperature << " degrees Celsius" << std::endl;
// 关闭NVML库
nvmlShutdown();
return 0;
}
```
请注意,此示例仅适用于NVIDIA显卡。对于其他显卡品牌的温度获取,您需要查找相应的API。
阅读全文