diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-11-22 10:30:04 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-11-27 01:25:10 +0100 |
commit | a0f9aef11bd3a692f9fa9c6069ca27200ef82893 (patch) | |
tree | 9b66bf55c56edabced026fe32f9a15ec1b361cb2 /tests | |
parent | cf2336ae6e9b0dd0db9369d0a0bfaf9ecf393cf9 (diff) |
Long live Q_GADGET_EXPORT!
Like Q_NAMESPACE_EXPORT for Q_NAMESPACE, this variant of Q_GADGET
allows passing an export macro. This is useful to avoid exporting the
whole class just to get the staticMetaObject hidden therein exported.
Before anyone asks: No, we don't need Q_OBJECT_EXPORT, because QObject
subclasses, being polymorphic, always need to have a class-level
export macro (to export their vtable), but while that technique also
works for value classes (the Q_GADGET audience), it is not desirable
for them, because it makes inline functions exported in Windows debug
builds, which is not what we want, because it needlessly restricts
what you can to with the inline functions (e.g. remove).
[ChangeLog][QtCore] Added the Q_GADGET_EXPORT macro, which is like
Q_GADGET, but allows passing an export macro (like Q_NAMESPACE_EXPORT
for Q_NAMESPACE).
Fixes: QTBUG-55458
Change-Id: I546297de1e8aa45d83381991bcd3fbca61e1eef0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index cd69ea893c..1fb153ac09 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -89,6 +89,8 @@ const char *string_hash_hash = STRING_HASH_HASH("baz"); Q_DECLARE_METATYPE(const QMetaObject*); +#define TESTEXPORTMACRO Q_DECL_EXPORT + namespace TestNonQNamespace { struct TestGadget { @@ -140,6 +142,22 @@ namespace TestQNamespace { Q_ENUM(TestGEnum2) }; + struct TestGadgetExport { + Q_GADGET_EXPORT(TESTEXPORTMACRO) + Q_CLASSINFO("key", "exported") + public: + enum class TestGeEnum1 { + Key1 = 20, + Key2 + }; + Q_ENUM(TestGeEnum1) + enum class TestGeEnum2 { + Key1 = 23, + Key2 + }; + Q_ENUM(TestGeEnum2) + }; + enum class TestFlag1 { None = 0, Flag1 = 1, @@ -158,8 +176,6 @@ namespace TestQNamespace { } -#define TESTEXPORTMACRO Q_DECL_EXPORT - namespace TestExportNamespace { Q_NAMESPACE_EXPORT(TESTEXPORTMACRO) enum class MyEnum { @@ -3954,6 +3970,12 @@ void tst_Moc::testQNamespace() checkEnum(TestQNamespace::TestGadget::staticMetaObject.enumerator(1), "TestGEnum2", {{"Key1", 23}, {"Key2", 24}}); + QCOMPARE(TestQNamespace::TestGadgetExport::staticMetaObject.enumeratorCount(), 2); + checkEnum(TestQNamespace::TestGadgetExport::staticMetaObject.enumerator(0), "TestGeEnum1", + {{"Key1", 20}, {"Key2", 21}}); + checkEnum(TestQNamespace::TestGadgetExport::staticMetaObject.enumerator(1), "TestGeEnum2", + {{"Key1", 23}, {"Key2", 24}}); + QMetaEnum meta = QMetaEnum::fromType<TestQNamespace::TestEnum1>(); QVERIFY(meta.isValid()); QCOMPARE(meta.name(), "TestEnum1"); |