From 485d9665ea446c76c5cc6f0b7751c4930f1d391e Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Fri, 7 Jan 2022 13:15:46 +0800 Subject: [PATCH] Fix build on Qt versions below 5.14 QStringView introduced in Qt 5.10.0 qExchange() introduced in Qt 5.14.0 qSwap() is deprecated, use std::swap() instead Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/common.pri | 2 +- framelesshelper_global.h | 14 ++++++++++++-- lib.pro | 2 +- qwinregistry_p.h | 13 ++++++++----- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/examples/common.pri b/examples/common.pri index 8d0a609..d3b6288 100644 --- a/examples/common.pri +++ b/examples/common.pri @@ -10,7 +10,7 @@ RESOURCES += $$PWD/images.qrc win32 { CONFIG += windeployqt CONFIG -= embed_manifest_exe - LIBS += -luser32 -lshell32 + LIBS += -luser32 -lshell32 -ladvapi32 RC_FILE = $$PWD/example.rc OTHER_FILES += $$PWD/example.manifest } diff --git a/framelesshelper_global.h b/framelesshelper_global.h index 64bceb0..bb43003 100644 --- a/framelesshelper_global.h +++ b/framelesshelper_global.h @@ -54,8 +54,14 @@ #define qAsConst(i) std::as_const(i) #endif -#if !defined(Q_OS_WINDOWS) || defined(FRAMELESSHELPER_TEST_UNIX) -#define FRAMELESSHELPER_USE_UNIX_VERSION +#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0)) +#define QStringView const QString & +#else +#include +#endif + +#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) +#define qExchange(a, b) std::exchange(a, b) #endif #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) @@ -64,6 +70,10 @@ #define Q_NODISCARD #endif +#if !defined(Q_OS_WINDOWS) || defined(FRAMELESSHELPER_TEST_UNIX) +#define FRAMELESSHELPER_USE_UNIX_VERSION +#endif + #ifndef FRAMELESSHELPER_NAMESPACE #define FRAMELESSHELPER_NAMESPACE __flh_ns #endif diff --git a/lib.pro b/lib.pro index 745b69d..308ca50 100644 --- a/lib.pro +++ b/lib.pro @@ -34,7 +34,7 @@ win32 { utilities_win32.cpp \ framelesshelper_win32.cpp \ qwinregistry.cpp - LIBS += -luser32 -lshell32 + LIBS += -luser32 -lshell32 -ladvapi32 RC_FILE = framelesshelper.rc } linux*: SOURCES += utilities_linux.cpp diff --git a/qwinregistry_p.h b/qwinregistry_p.h index 2201a58..62f95a9 100644 --- a/qwinregistry_p.h +++ b/qwinregistry_p.h @@ -50,13 +50,12 @@ // We mean it. // -#include +#include "framelesshelper_global.h" #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) #include #else // QT_VERSION < QT_VERSION_CHECK(5, 14, 0) #include #include -#include #include QT_BEGIN_NAMESPACE @@ -72,9 +71,13 @@ public: ~QWinRegistryKey(); QWinRegistryKey(QWinRegistryKey &&other) noexcept - : m_key(qExchange(other.m_key, nullptr)) {} - QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QWinRegistryKey) - void swap(QWinRegistryKey &other) noexcept { qSwap(m_key, other.m_key); } + : m_key(std::exchange(other.m_key, nullptr)) {} + QWinRegistryKey &operator=(QWinRegistryKey &&other) noexcept { + QWinRegistryKey moved(std::move(other)); + swap(moved); + return *this; + } + void swap(QWinRegistryKey &other) noexcept { std::swap(m_key, other.m_key); } bool isValid() const { return m_key != nullptr; } operator HKEY() const { return m_key; }