diff --git a/src/corelib/kernel/qwinregistry.cpp b/src/corelib/kernel/qwinregistry.cpp index d2373165771..59d30fd4a35 100644 --- a/src/corelib/kernel/qwinregistry.cpp +++ b/src/corelib/kernel/qwinregistry.cpp @@ -125,10 +125,4 @@ QString QWinRegistryKey::stringValue(QStringView subKey) const return value(subKey).value_or(QString()); } -std::pair QWinRegistryKey::dwordValue(QStringView subKey) const -{ - const std::optional val = value(subKey); - return {val.value_or(0), val.has_value()}; -} - QT_END_NAMESPACE diff --git a/src/corelib/kernel/qwinregistry_p.h b/src/corelib/kernel/qwinregistry_p.h index 20b2d10dd7e..e767e92f92a 100644 --- a/src/corelib/kernel/qwinregistry_p.h +++ b/src/corelib/kernel/qwinregistry_p.h @@ -58,7 +58,6 @@ public: // ### TODO: Remove once all usages are migrated to new interface. QString stringValue(QStringView subKey) const; - std::pair dwordValue(QStringView subKey) const; private: HKEY m_key = nullptr; diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index 7874c221748..8e40abab2e7 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -538,9 +538,9 @@ void QWinTimeZonePrivate::init(const QByteArray &ianaId) QWinRegistryKey dynamicKey(HKEY_LOCAL_MACHINE, dynamicKeyPath); if (dynamicKey.isValid()) { // Find out the start and end years stored, then iterate over them - const auto startYear = dynamicKey.dwordValue(L"FirstEntry"); - const auto endYear = dynamicKey.dwordValue(L"LastEntry"); - for (int year = int(startYear.first); year <= int(endYear.first); ++year) { + const int startYear = dynamicKey.value(L"FirstEntry").value_or(0); + const int endYear = dynamicKey.value(L"LastEntry").value_or(0); + for (int year = startYear; year <= endYear; ++year) { bool ruleOk; QWinTransitionRule rule = readRegistryRule(dynamicKey, diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 11a9290a2eb..88e9da5557c 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1446,11 +1446,9 @@ void QWindowsContext::setAsyncExpose(bool value) DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue) { - const auto value = - QWinRegistryKey(HKEY_CURRENT_USER, - LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)") - .dwordValue(subKey); - return value.second ? value.first : defaultValue; + const auto advancedSettings = QWinRegistryKey( + HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)"); + return advancedSettings.value(subKey).value_or(defaultValue); } static inline bool isEmptyRect(const RECT &rect) diff --git a/src/plugins/platforms/windows/qwindowscursor.cpp b/src/plugins/platforms/windows/qwindowscursor.cpp index b4168861206..489d7a40871 100644 --- a/src/plugins/platforms/windows/qwindowscursor.cpp +++ b/src/plugins/platforms/windows/qwindowscursor.cpp @@ -668,16 +668,16 @@ void QWindowsCursor::setPos(const QPoint &pos) */ QSize QWindowsCursor::size() const { - const QPair cursorSizeSetting = + const auto cursorSizeSetting = QWinRegistryKey(HKEY_CURRENT_USER, LR"(Control Panel\Cursors)") - .dwordValue(L"CursorBaseSize"); + .value(L"CursorBaseSize"); const int baseSize = screenCursorSize(m_screen).width() / 2; - if (!cursorSizeSetting.second) + if (!cursorSizeSetting) return QSize(baseSize / 2, baseSize / 2); // The registry values are dpi-independent, so we need to scale the result. - int cursorSizeValue = cursorSizeSetting.first * m_screen->logicalDpi().first - / m_screen->logicalBaseDpi().first; + int cursorSizeValue = *cursorSizeSetting * m_screen->logicalDpi().first + / m_screen->logicalBaseDpi().first; // map from registry value 32-256 to 0-14, and from there to pixels cursorSizeValue = (cursorSizeValue - 2 * baseSize) / baseSize; diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index a3c16b27271..918a4823380 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -1167,9 +1167,11 @@ Qt::ColorScheme QWindowsTheme::queryColorScheme() if (queryHighContrast()) return Qt::ColorScheme::Unknown; - const auto setting = QWinRegistryKey(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)") - .dwordValue(L"AppsUseLightTheme"); - return setting.second && setting.first == 0 ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light; + QWinRegistryKey personalizeKey{ + HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)" + }; + const bool useDarkTheme = personalizeKey.value(L"AppsUseLightTheme") == 0; + return useDarkTheme ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light; } bool QWindowsTheme::queryHighContrast() diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 644741f16e0..7adf1cb9b78 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1205,8 +1205,8 @@ void tst_QFileInfo::fileTimes() const auto disabledAccessTimes = QWinRegistryKey(HKEY_LOCAL_MACHINE, LR"(SYSTEM\CurrentControlSet\Control\FileSystem)") - .dwordValue(L"NtfsDisableLastAccessUpdate"); - if (disabledAccessTimes.second && disabledAccessTimes.first != 0) + .value(L"NtfsDisableLastAccessUpdate"); + if (disabledAccessTimes.value_or(0) != 0) noAccessTime = true; #endif diff --git a/tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp b/tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp index a5dca8a3d5f..efaeed3300e 100644 --- a/tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp +++ b/tests/auto/corelib/kernel/qwinregistrykey/tst_qwinregistrykey.cpp @@ -225,15 +225,14 @@ void tst_qwinregistrykey::qwinregistrykey() QVERIFY(registry.stringValue(TEST_NOT_EXIST.first).isEmpty()); { - const auto value = registry.dwordValue(TEST_DWORD.first); - QVERIFY(value.second); - QCOMPARE(value.first, TEST_DWORD.second); + const auto value = registry.value(TEST_DWORD.first); + QVERIFY(value); + QCOMPARE(*value, TEST_DWORD.second); } { - const auto value = registry.dwordValue(TEST_NOT_EXIST.first); - QVERIFY(!value.second); - QCOMPARE(value.first, DWORD(0)); + const auto value = registry.value(TEST_NOT_EXIST.first); + QVERIFY(!value); } }