qt 获取系统主机名、UID序列号、以及磁盘空间等其他信息

使用qt接口获取系统主机名、UID序列号、以及磁盘空间、当前网络传输速率,显卡参数等

void logPCInfo()

{

LOG_FUN(LOG_LEVEL_INFO, "Host Name: %s", QSysInfo::machineHostName().toStdString().c_str());

LOG_FUN(LOG_LEVEL_INFO, "Machine Unique Id: %s", QSysInfo::machineUniqueId().toStdString().c_str());

LOG_FUN(LOG_LEVEL_INFO, "Oper System Name: %s", QSysInfo::prettyProductName().toStdString().c_str());

LOG_FUN(LOG_LEVEL_INFO, "CPU Architecture: %s", QSysInfo::currentCpuArchitecture().toStdString().c_str());

CPUID cpuID[3] = { CPUID(2147483650), CPUID(2147483651), CPUID(2147483652) };

std::string vendor;

for (int i = 0; i < 3; i++) {

vendor += std::string((const char *)&cpuID[i].EAX(), 4);

vendor += std::string((const char *)&cpuID[i].EBX(), 4);

vendor += std::string((const char *)&cpuID[i].ECX(), 4);

vendor += std::string((const char *)&cpuID[i].EDX(), 4);

}

LOG_FUN(LOG_LEVEL_INFO, "CPU Info: %s", vendor.c_str());

int nMB = 1024 * 1024;

MEMORYSTATUSEX statex;

statex.dwLength = sizeof(statex);

GlobalMemoryStatusEx(&statex);

ULONGLONG totalMem = statex.ullTotalPhys / nMB;

ULONGLONG freeMem = statex.ullAvailPhys / nMB;

LOG_FUN(LOG_LEVEL_INFO, "Memory Space: Total %d MB, Free Space: %d MB", totalMem, freeMem);

QStorageInfo SD;

SD.setPath(GetDataDir());

SD.refresh();

LOG_FUN(LOG_LEVEL_INFO, "Physical Disk Space: %d MB, Available Space: %d MB", SD.bytesTotal() / nMB, SD.bytesAvailable() / nMB);

SYSTEM_POWER_STATUS powerStatus;

if (GetSystemPowerStatus(&powerStatus))

{

if (powerStatus.ACLineStatus == 1)

{

LOG_FUN(LOG_LEVEL_INFO, "Power Status: The laptop is plugged in");

}

else if (powerStatus.ACLineStatus == 0)

{

LOG_FUN(LOG_LEVEL_INFO, "Power Status: The laptop is running on battery");

}

else

{

LOG_FUN(LOG_LEVEL_INFO, "Power Status: The AC line status is unknown");

}

}

else

{

LOG_FUN(LOG_LEVEL_INFO, "Power Status: Failed to get system power status");

}

IP_ADAPTER_INFO* adapterInfo;

ULONG bufferSize = sizeof(IP_ADAPTER_INFO);

adapterInfo = (IP_ADAPTER_INFO*)malloc(bufferSize);

if (GetAdaptersInfo(adapterInfo, &bufferSize) == ERROR_BUFFER_OVERFLOW) {

free(adapterInfo);

adapterInfo = (IP_ADAPTER_INFO*)malloc(bufferSize);

GetAdaptersInfo(adapterInfo, &bufferSize);

}

IP_ADAPTER_INFO* currentAdapter = adapterInfo;

while (currentAdapter) {

QString ipaddr = QString::fromLatin1(currentAdapter->IpAddressList.IpAddress.String, 16);

if (ipaddr.contains("169.254.1.10"))

{

QString description = QString::fromLatin1(currentAdapter->Description, 132);

m_activeNetCardName = description;

auto activeSpeed = GetNetWorkSpeed();

LOG_FUN(LOG_LEVEL_INFO, "Active Network card : %s, active speed: %dMbps", description.toStdString().c_str(), activeSpeed / 1000 /1000);

}

currentAdapter = currentAdapter->Next;

}

free(adapterInfo);

QProcess cudaProcess;

cudaProcess.start("nvidia-smi");

cudaProcess.waitForFinished();

QString cudaInfo = QString::fromLocal8Bit(cudaProcess.readAllStandardOutput());

auto driverIndex = cudaInfo.indexOf("Driver Version");

auto cudaIndex = cudaInfo.indexOf("CUDA Version");

auto driverVer = cudaInfo.mid(driverIndex, cudaIndex - driverIndex);

LOG_FUN(LOG_LEVEL_INFO, "GPU %s", driverVer.toStdString().c_str());

}

相关推荐
zzlyx999 分钟前
用C#采用Avalonia+Mapsui在离线地图上插入图片画信号扩散图
java·开发语言·c#
Yue丶越30 分钟前
【C语言】自定义类型:结构体
c语言·开发语言
合作小小程序员小小店31 分钟前
桌面开发,点餐管理系统开发,基于C#,winform,sql server数据库
开发语言·数据库·sql·microsoft·c#
笃行客从不躺平36 分钟前
线程池监控是什么
java·开发语言
星轨初途37 分钟前
C++的输入输出(上)(算法竞赛类)
开发语言·c++·经验分享·笔记·算法
极地星光1 小时前
Qt/C++ 单例模式深度解析:饿汉式与懒汉式实战指南
c++·qt·单例模式
dangdang___go1 小时前
动态内存管理||malloc和free.realloc和calloc
c语言·开发语言·算法·动态内存管理
YA3331 小时前
mcp-grafana mcp 使用stdio报错
java·开发语言
周杰伦_Jay1 小时前
【Go 语言主流 Web】 框架详细解析
开发语言·后端·微服务·架构·golang
PfCoder2 小时前
WinForm真入门(20)——StatusStrip控件解析
开发语言·windows·c#·winform·statusstrip