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

}

相关推荐
我是陈泽5 分钟前
一行 Python 代码能实现什么丧心病狂的功能?圣诞树源代码
开发语言·python·程序员·编程·python教程·python学习·python教学
优雅的小武先生16 分钟前
QT中的按钮控件和comboBox控件和spinBox控件无法点击的bug
开发语言·qt·bug
Death20016 分钟前
使用Qt进行TCP和UDP网络编程
网络·c++·qt·tcp/ip
虽千万人 吾往矣22 分钟前
golang gorm
开发语言·数据库·后端·tcp/ip·golang
创作小达人24 分钟前
家政服务|基于springBoot的家政服务平台设计与实现(附项目源码+论文+数据库)
开发语言·python
郭二哈27 分钟前
C++——list
开发语言·c++·list
杨荧28 分钟前
【JAVA开源】基于Vue和SpringBoot的洗衣店订单管理系统
java·开发语言·vue.js·spring boot·spring cloud·开源
ZPC821035 分钟前
Python使用matplotlib绘制图形大全(曲线图、条形图、饼图等)
开发语言·python·matplotlib
镜花照无眠36 分钟前
Python爬虫使用实例-mdrama
开发语言·爬虫·python
aaasssdddd961 小时前
python和c
c语言·开发语言·python