path: root/src/corelib/kernel/qobjectdefs.h
diff options
authorGiuseppe D'Angelo <>2019-04-30 09:39:21 +0200
committerGiuseppe D'Angelo <>2019-06-28 06:47:29 +0200
commitf66c1db16c050c9d685a44a38ad7c5cf9f6fcc96 (patch)
tree53e38e8714d493e321e0437f4d4f59bd6f4aff10 /src/corelib/kernel/qobjectdefs.h
parent8f0e3ad5188d17c88f624eeea9a67ab17e55cc6f (diff)
A recurring problem with the Q_NAMESPACE macro is that it declares an object (staticMetaObject) in the surrounding namespace. That object lacks any export/import qualification to make it usable with shared libraries. Introduce therefore another macro to work around this issue, allowing the user to prefix the object with an exporting macro, f.i. like this: Q_NAMESPACE_EXPORT(Q_CORE_EXPORT) The old macro can simply then be rewritten in terms of this new one, supplying an empty export macro. Note that NOT passing an argument to a macro expecting one is well defined behavior in C99 -- the macro will expand an empty token. Of course, MSVC doesn't like this and emits warnings. As a workaround, use a variadic macro. [ChangeLog][QtCore] Added the new Q_NAMESPACE_EXPORT macro. It can be used just like Q_NAMESPACE to add meta-object information to a namespace; however it also supports exporting of such information from shared libraries. [ChangeLog][Potentially Source-Incompatible Changes] Prefixing Q_NAMESPACE with an export macro may no longer work. Use the new Q_NAMESPACE_EXPORT macro for that use case. Fixes: QTBUG-68014 Change-Id: Ib044a555ace1f77ae8e0244d824ec473550f3d8e Reviewed-by: Edward Welbourne <> Reviewed-by: Qt CI Bot <> Reviewed-by: BogDan Vatra <>
Diffstat (limited to 'src/corelib/kernel/qobjectdefs.h')
1 files changed, 7 insertions, 3 deletions
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 4d5ac4dcb2..ef22b6e67f 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -201,12 +201,16 @@ private: \
QT_ANNOTATE_CLASS(qt_qgadget, "") \
-/* qmake ignore Q_NAMESPACE */
-#define Q_NAMESPACE \
- extern const QMetaObject staticMetaObject; \
+/* qmake ignore Q_NAMESPACE_EXPORT */
+#define Q_NAMESPACE_EXPORT(...) \
+ extern __VA_ARGS__ const QMetaObject staticMetaObject; \
QT_ANNOTATE_CLASS(qt_qnamespace, "") \
+/* qmake ignore Q_NAMESPACE */
+ /*end*/
#else // Q_MOC_RUN