aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-12-09 16:06:36 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2020-12-10 10:57:58 +0100
commitb6a164891537d6d3a515d78a44b0de6595a170c2 (patch)
treea66c516b467b739a1ce761dc058f898b19bc63b7
parentfb4de27768935393744cbd67e9789d325e70e742 (diff)
Support namespaced QML_ELEMENT
Fixes: QTBUG-87266 Change-Id: Iad8c7765b339c5498f541702bbf7df64164f5358 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/qml/qqmlprivate.h11
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp8
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h10
3 files changed, 26 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlprivate.h b/src/qml/qml/qqmlprivate.h
index 6d0c176bdd..a2cd9452ac 100644
--- a/src/qml/qml/qqmlprivate.h
+++ b/src/qml/qml/qqmlprivate.h
@@ -671,8 +671,15 @@ namespace QQmlPrivate
inline const char *classElementName(const QMetaObject *metaObject)
{
const char *elementName = classInfo(metaObject, "QML.Element");
- if (qstrcmp(elementName, "auto") == 0)
- return metaObject->className();
+ if (qstrcmp(elementName, "auto") == 0) {
+ const char *strippedClassName = metaObject->className();
+ for (const char *c = strippedClassName; *c != '\0'; c++) {
+ if (*c == ':')
+ strippedClassName = c + 1;
+ }
+
+ return strippedClassName;
+ }
if (qstrcmp(elementName, "anonymous") == 0)
return nullptr;
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
index f8ffa1166f..ae160e0d33 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
@@ -117,4 +117,12 @@ void tst_qmltyperegistrar::implementsInterfaces()
QVERIFY(qmltypesData.contains("interfaces: [\"Interface\", \"Interface2\"]"));
}
+void tst_qmltyperegistrar::namespacedElement()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine);
+ c.setData("import QML\nimport QmlTypeRegistrarTest 1.0\nElement {}", QUrl());
+ QVERIFY2(!c.isError(), qPrintable(c.errorString()));
+}
+
QTEST_MAIN(tst_qmltyperegistrar)
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
index b13debcf1b..211119a654 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
@@ -132,6 +132,14 @@ public:
QProperty<int> someProperty;
};
+namespace Namespace {
+ class Element : public QObject
+ {
+ Q_OBJECT
+ QML_ELEMENT
+ };
+}
+
class tst_qmltyperegistrar : public QObject
{
Q_OBJECT
@@ -148,7 +156,7 @@ private slots:
void restrictToImportVersion();
void pastMajorVersions();
void implementsInterfaces();
-
+ void namespacedElement();
private:
QByteArray qmltypesData;
};