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

}

相关推荐
帅那个帅24 分钟前
PHP里面的抽象类和接口类
开发语言·php
咖啡の猫6 小时前
Python字典推导式
开发语言·python
leiming67 小时前
C++ vector容器
开发语言·c++·算法
SystickInt7 小时前
C语言 strcpy和memcpy 异同/区别
c语言·开发语言
CS Beginner7 小时前
【C语言】windows下编译mingw版本的glew库
c语言·开发语言·windows
FJW0208147 小时前
Python_work4
开发语言·python
大学生资源网8 小时前
java毕业设计之儿童福利院管理系统的设计与实现(源码+)
java·开发语言·spring boot·mysql·毕业设计·源码·课程设计
JasmineWr8 小时前
JVM栈空间的使用和优化
java·开发语言
Poetinthedusk8 小时前
C#实现图片统一位深
开发语言·c#
吴佳浩 Alben8 小时前
Python入门指南(四)
开发语言·后端·python