summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-05-04 15:17:29 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-05-08 14:04:41 +0000
commitbdbf6a53c0ab8a7f6ea5586767a6ed818e3d555e (patch)
treeca40f396b7c4eb5e3b28b4f5bd28c806c8fdef95
parent4115adb95f2670b96b036215abe98e0f40c58b95 (diff)
Fix loading of composite singletons from resources
Commit f6bbeeb417102c61e8bf23f41e412ed9753a348d began normalizing the resource urls in the type loader, which broke loading of qml singletons from resources, as the normalized url is also used for the "pragma singleton" verification to check that the singleton is in the meta-type registry. If the registration was done with a non-normalized url, the check would fail with a misleading error message. Task-number: QTBUG-68025 Change-Id: I1093ee0cbee884b4a51195c302c8908f748e747e Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
-rw-r--r--src/qml/qml/qqmlmetatype.cpp11
-rw-r--r--src/qml/qml/qqmlmetatype_p.h2
-rw-r--r--src/qml/qml/qqmltypeloader.cpp4
-rw-r--r--tests/auto/qml/qqmlmetatype/qqmlmetatype.pro4
-rw-r--r--tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp14
5 files changed, 27 insertions, 8 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 8fda7f6f77..d842a7795f 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -424,7 +424,7 @@ QQmlType::QQmlType(QQmlMetaTypeData *data, const QString &elementName, const QQm
d->version_min = type.versionMinor;
d->extraData.sd->singletonInstanceInfo = new SingletonInstanceInfo;
- d->extraData.sd->singletonInstanceInfo->url = type.url;
+ d->extraData.sd->singletonInstanceInfo->url = QQmlTypeLoader::normalize(type.url);
d->extraData.sd->singletonInstanceInfo->typeName = QString::fromUtf8(type.typeName);
}
@@ -477,7 +477,7 @@ QQmlType::QQmlType(QQmlMetaTypeData *data, const QString &elementName, const QQm
d->version_maj = type.versionMajor;
d->version_min = type.versionMinor;
- d->extraData.fd->url = type.url;
+ d->extraData.fd->url = QQmlTypeLoader::normalize(type.url);
}
QQmlType::QQmlType()
@@ -1710,7 +1710,7 @@ QQmlType QQmlMetaType::registerCompositeSingletonType(const QQmlPrivate::Registe
addTypeToData(dtype.priv(), data);
QQmlMetaTypeData::Files *files = fileImport ? &(data->urlToType) : &(data->urlToNonFileImportType);
- files->insertMulti(type.url, dtype.priv());
+ files->insertMulti(QQmlTypeLoader::normalize(type.url), dtype.priv());
return dtype;
}
@@ -1731,7 +1731,7 @@ QQmlType QQmlMetaType::registerCompositeType(const QQmlPrivate::RegisterComposit
addTypeToData(dtype.priv(), data);
QQmlMetaTypeData::Files *files = fileImport ? &(data->urlToType) : &(data->urlToNonFileImportType);
- files->insertMulti(type.url, dtype.priv());
+ files->insertMulti(QQmlTypeLoader::normalize(type.url), dtype.priv());
return dtype;
}
@@ -2253,8 +2253,9 @@ QQmlType QQmlMetaType::qmlType(int userType)
Returns null if no such type is registered.
*/
-QQmlType QQmlMetaType::qmlType(const QUrl &url, bool includeNonFileImports /* = false */)
+QQmlType QQmlMetaType::qmlType(const QUrl &unNormalizedUrl, bool includeNonFileImports /* = false */)
{
+ const QUrl url = QQmlTypeLoader::normalize(unNormalizedUrl);
QMutexLocker lock(metaTypeDataLock());
QQmlMetaTypeData *data = metaTypeData();
diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h
index cd7afc8a01..51bf485a3e 100644
--- a/src/qml/qml/qqmlmetatype_p.h
+++ b/src/qml/qml/qqmlmetatype_p.h
@@ -96,7 +96,7 @@ public:
static QQmlType qmlType(const QMetaObject *);
static QQmlType qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor);
static QQmlType qmlType(int);
- static QQmlType qmlType(const QUrl &url, bool includeNonFileImports = false);
+ static QQmlType qmlType(const QUrl &unNormalizedUrl, bool includeNonFileImports = false);
static QQmlPropertyCache *propertyCache(const QMetaObject *metaObject);
static QQmlPropertyCache *propertyCache(const QQmlType &type, int minorVersion);
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index a0f7ec967c..9856a0be80 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -1667,7 +1667,7 @@ QQmlTypeData *QQmlTypeLoader::getType(const QUrl &unNormalizedUrl, Mode mode)
(QQmlFile::urlToLocalFileOrQrc(unNormalizedUrl).isEmpty() ||
!QDir::isRelativePath(QQmlFile::urlToLocalFileOrQrc(unNormalizedUrl))));
- QUrl url = normalize(unNormalizedUrl);
+ const QUrl url = normalize(unNormalizedUrl);
LockHolder<QQmlTypeLoader> holder(this);
@@ -1732,7 +1732,7 @@ QQmlScriptBlob *QQmlTypeLoader::getScript(const QUrl &unNormalizedUrl)
(QQmlFile::urlToLocalFileOrQrc(unNormalizedUrl).isEmpty() ||
!QDir::isRelativePath(QQmlFile::urlToLocalFileOrQrc(unNormalizedUrl))));
- QUrl url = normalize(unNormalizedUrl);
+ const QUrl url = normalize(unNormalizedUrl);
LockHolder<QQmlTypeLoader> holder(this);
diff --git a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro
index 0d8de91931..345bc59615 100644
--- a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro
+++ b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro
@@ -6,4 +6,8 @@ macx:CONFIG -= app_bundle
TESTDATA = data/*
include (../../shared/util.pri)
+qmlfiles.files = data/CompositeType.qml
+qmlfiles.prefix = /tstqqmlmetatype
+RESOURCES += qmlfiles
+
QT += core-private gui-private qml-private testlib
diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
index ff3361ff82..1d0d353668 100644
--- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
+++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
@@ -62,6 +62,8 @@ private slots:
void defaultObject();
void unregisterCustomType();
void unregisterCustomSingletonType();
+
+ void normalizeUrls();
};
class TestType : public QObject
@@ -523,6 +525,18 @@ void tst_qqmlmetatype::unregisterCustomSingletonType()
}
}
+void tst_qqmlmetatype::normalizeUrls()
+{
+ const QUrl url("qrc:///tstqqmlmetatype/data/CompositeType.qml");
+ QVERIFY(!QQmlMetaType::qmlType(url).isValid());
+ const auto registrationId = qmlRegisterType(url, "Test", 1, 0, "ResourceCompositeType");
+ QVERIFY(QQmlMetaType::qmlType(url, /*includeNonFileImports=*/true).isValid());
+ QUrl normalizedURL("qrc:/tstqqmlmetatype/data/CompositeType.qml");
+ QVERIFY(QQmlMetaType::qmlType(normalizedURL, /*includeNonFileImports=*/true).isValid());
+ qmlUnregisterType(registrationId);
+ QVERIFY(!QQmlMetaType::qmlType(url, /*includeNonFileImports=*/true).isValid());
+}
+
QTEST_MAIN(tst_qqmlmetatype)
#include "tst_qqmlmetatype.moc"