本文主要是介绍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());
}
这篇关于qt 获取系统主机名、UID序列号、以及磁盘空间等其他信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!