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());

}

相关推荐
Andy2 小时前
Python基础语法4
开发语言·python
但要及时清醒2 小时前
ArrayList和LinkedList
java·开发语言
孚亭2 小时前
Swift添加字体到项目中
开发语言·ios·swift
hweiyu002 小时前
Go、DevOps运维开发实战(视频教程)
开发语言·golang·运维开发
mm-q29152227292 小时前
Python+Requests零基础系统掌握接口自动化测试
开发语言·python
星星火柴9363 小时前
笔记 | C++面向对象高级开发
开发语言·c++·笔记·学习
码界奇点3 小时前
Rust 性能优化全流程从 flamegraph 定位瓶颈到 unsafe 与 SIMD 加速响应快
开发语言·性能优化·rust·simulated annealing
丛雨要玩游戏4 小时前
字符函数和字符串函数
c语言·开发语言·算法
八个程序员4 小时前
自定义函数(C++)
开发语言·c++·算法
ad钙奶长高高4 小时前
【C语言】初始C语言
c语言·开发语言·算法