From 80996d2e5d6d04b08452cf507f6ced7d8a09068c Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Fri, 20 May 2022 14:22:09 +0800 Subject: [PATCH] qglobal: resolve one Qt6 TODO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tested with MSVC 2022 locally and this change doesn't break the bootstrapped builds. Change-Id: Ieeb9a77035d889b9c1ed0c0c3488ac8802879282 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/global/qglobal.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 1d20b4f27a2..cd78dfde1a1 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -3003,18 +3003,10 @@ QByteArray QSysInfo::machineUniqueId() } #elif defined(Q_OS_WIN) // Let's poke at the registry - // ### Qt 6: Use new helpers from qwinregistry.cpp (once bootstrap builds are obsolete) - HKEY key = NULL; - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ | KEY_WOW64_64KEY, &key) - == ERROR_SUCCESS) { - wchar_t buffer[UuidStringLen + 1]; - DWORD size = sizeof(buffer); - bool ok = (RegQueryValueEx(key, L"MachineGuid", NULL, NULL, (LPBYTE)buffer, &size) == - ERROR_SUCCESS); - RegCloseKey(key); - if (ok) - return QStringView(buffer, (size - 1) / 2).toLatin1(); - } + const QString machineGuid = QWinRegistryKey(HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Cryptography)") + .stringValue(u"MachineGuid"_s); + if (!machineGuid.isEmpty()) + return machineGuid.toLatin1(); #endif return QByteArray(); }