path: root/tests/auto/tools/moc/tst_moc.cpp
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 /tests/auto/tools/moc/tst_moc.cpp
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 'tests/auto/tools/moc/tst_moc.cpp')
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index ec4a44e672..b88d929ca9 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -149,6 +149,17 @@ namespace TestQNamespace {
+namespace TestExportNamespace {
+ enum class MyEnum {
+ Key1, Key2
+ };
+ Q_ENUM_NS(MyEnum)
template <bool b> struct QTBUG_31218 {};
@@ -3893,6 +3904,10 @@ void tst_Moc::testQNamespace()
QCOMPARE(meta.enclosingMetaObject(), &TestQNamespace::staticMetaObject);
QCOMPARE(meta.keyCount(), 2);
+ QCOMPARE(TestExportNamespace::staticMetaObject.enumeratorCount(), 1);
+ checkEnum(TestExportNamespace::staticMetaObject.enumerator(0), "MyEnum",
+ {{"Key1", 0}, {"Key2", 1}});
QCOMPARE(FooNamespace::staticMetaObject.enumeratorCount(), 1);
QCOMPARE(FooNamespace::FooNestedNamespace::staticMetaObject.enumeratorCount(), 2);
QCOMPARE(FooNamespace::FooNestedNamespace::FooMoreNestedNamespace::staticMetaObject.enumeratorCount(), 1);