QString getCpu()
{
static QString model = "";
#ifdef Q_OS_WIN
if (model.isEmpty()) {
std::array<int, 4> cpui;
std::vector<std::array<int, 4>> extdata;
// Calling __cpuid with 0x80000000 as the function_id argument
// gets the number of the highest valid extended ID.
__cpuid(cpui.data(), 0x80000000);
int nExIds = cpui[0];
char brand[0x40];
memset(brand, 0, sizeof(brand));
for (int i = 0x80000000; i <= nExIds; ++i) {
__cpuidex(cpui.data(), i, 0);
extdata.push_back(cpui);
}
// Interpret CPU brand string if reported
if (nExIds >= 0x80000004) {
memcpy(brand, extdata[2].data(), sizeof(cpui));
memcpy(brand + 16, extdata[3].data(), sizeof(cpui));
memcpy(brand + 32, extdata[4].data(), sizeof(cpui));
model = QString::fromStdString(brand);
}
}
#endif
return model.trimmed();
}