From ea89d0a36ca5b17998c62880f4802228314b1e2d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 3 Feb 2022 15:44:08 -0800 Subject: [PATCH] qglobal: add a way to selectively export in Qt 6 XOR Qt 7 Because at least one compiler *cough*MSVC*cough* is unable to dllexport a method that is in a dllexport'ed class. Change-Id: I54f205f6b7314351b078fffd16d06b4e6ef0c086 Reviewed-by: Marc Mutz Reviewed-by: Edward Welbourne --- doc/global/qt-cpp-defines.qdocconf | 4 +++- src/corelib/global/qglobal.h | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/global/qt-cpp-defines.qdocconf b/doc/global/qt-cpp-defines.qdocconf index 0a49b37a02..5c762083a2 100644 --- a/doc/global/qt-cpp-defines.qdocconf +++ b/doc/global/qt-cpp-defines.qdocconf @@ -208,7 +208,9 @@ Cpp.ignoredirectives += \ QT_WARNING_DISABLE_INTEL \ QT_WARNING_DISABLE_MSVC \ Q_ATTRIBUTE_FORMAT_PRINTF \ - Q_MV_IOS + Q_MV_IOS \ + QT6_ONLY \ + QT7_ONLY # Qt 6: Remove falsehoods += \ diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 1808d01389..130b18a19e 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -107,6 +107,24 @@ #define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1) #define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.") +/* + helper macros to make some simple code work active in Qt 6 or Qt 7 only, + like: + struct QT6_ONLY(Q_CORE_EXPORT) QTrivialClass + { + void QT7_ONLY(Q_CORE_EXPORT) void operate(); + } +*/ +#if QT_VERSION_MAJOR == 7 +# define QT7_ONLY(...) __VA_ARGS__ +# define QT6_ONLY(...) +#elif QT_VERSION_MAJOR == 6 +# define QT7_ONLY(...) +# define QT6_ONLY(...) __VA_ARGS__ +#else +# error Qt major version not 6 or 7 +#endif + /* These two macros makes it possible to turn the builtin line expander into a * string literal. */ #define QT_STRINGIFY2(x) #x