From bb296168f426d7e646c0208427f25687f96e2693 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Mon, 20 Aug 2018 13:48:37 +0200 Subject: Provide option to skip registration of enum classes unscoped Enums classes are registered unscoped which leads to clashes in the following cases: 1. Two different enums contain the same values 2. The name of an enum class is the same as an enum value In the 2nd case you can not even access the scoped enum at all because it will be overwritten by the primitive type. Users can now add a class info to the meta type to disable the unscoped registration which solves all clashes. The default is kept as is. class MyClass : public QObject { Q_OBJECT Q_CLASSINFO("RegisterEnumClassesUnscoped", "false") public: ... }; [ChangeLog][QtQml] Added option to disable unscoped registration of enum classes. Change-Id: Ifa4197a14a252575e8a25ae56fb6ee479addf80b Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp') diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 97727c1794..157fd500ad 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -218,6 +219,8 @@ private slots: void lowercaseEnumCompileTime_data(); void lowercaseEnumCompileTime(); void scopedEnum(); + void scopedEnumsWithNameClash(); + void scopedEnumsWithResolvedNameClash(); void qmlEnums(); void literals_data(); void literals(); @@ -3793,6 +3796,40 @@ void tst_qqmllanguage::scopedEnum() QCOMPARE(o->property("noScope").toInt(), (int)MyTypeObject::MyScopedEnum::ScopedVal2); } +void tst_qqmllanguage::scopedEnumsWithNameClash() +{ + auto typeId = qmlRegisterUncreatableType("ScopedEnumsWithNameClashTest", 1, 0, "ScopedEnum", "Dummy reason"); + auto registryGuard = qScopeGuard([typeId]() { + qmlUnregisterType(typeId); + }); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("scopedEnumsWithNameClash.qml")); + + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "Previously registered enum will be overwritten due to name clash: ScopedEnumsWithNameClash.ScopedVal1"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "Previously registered enum will be overwritten due to name clash: ScopedEnumsWithNameClash.ScopedVal2"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "Previously registered enum will be overwritten due to name clash: ScopedEnumsWithNameClash.ScopedVal3"); + + QScopedPointer obj(component.create()); + QVERIFY(obj != nullptr); + QVERIFY(obj->property("success").toBool()); +} + +void tst_qqmllanguage::scopedEnumsWithResolvedNameClash() +{ + auto typeId = qmlRegisterUncreatableType("ScopedEnumsWithResolvedNameClashTest", 1, 0, "ScopedEnum", "Dummy reason"); + auto registryGuard = qScopeGuard([typeId]() { + qmlUnregisterType(typeId); + }); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("scopedEnumsWithResolvedNameClash.qml")); + + QScopedPointer obj(component.create()); + QVERIFY(obj != nullptr); + QVERIFY(obj->property("success").toBool()); +} + void tst_qqmllanguage::qmlEnums() { QQmlEngine engine; -- cgit v1.2.3