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

}

相关推荐
ajassi20004 小时前
开源 C++ QT Widget 开发(十五)多媒体--音频播放
linux·c++·qt·开源
CodeCraft Studio4 小时前
PDF处理控件Aspose.PDF教程:使用 Python 将 PDF 转换为 Base64
开发语言·python·pdf·base64·aspose·aspose.pdf
零点零一4 小时前
VS+QT的编程开发工作:关于QT VS tools的使用 qt的官方帮助
开发语言·qt
lingchen19066 小时前
MATLAB的数值计算(三)曲线拟合与插值
开发语言·matlab
gb42152877 小时前
java中将租户ID包装为JSQLParser的StringValue表达式对象,JSQLParser指的是?
java·开发语言·python
一朵梨花压海棠go7 小时前
html+js实现表格本地筛选
开发语言·javascript·html·ecmascript
蒋星熠7 小时前
Flutter跨平台工程实践与原理透视:从渲染引擎到高质产物
开发语言·python·算法·flutter·设计模式·性能优化·硬件工程
翻滚丷大头鱼7 小时前
Java 集合Collection—List
java·开发语言
aramae8 小时前
C++ -- 模板
开发语言·c++·笔记·其他
胡耀超8 小时前
4、Python面向对象编程与模块化设计
开发语言·python·ai·大模型·conda·anaconda