aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlimport.cpp2
-rw-r--r--tests/auto/qml/qqmlimport/data/interceptQmldir.qml7
-rw-r--r--tests/auto/qml/qqmlimport/data/intercepted/View.qml5
-rw-r--r--tests/auto/qml/qqmlimport/data/intercepted/qmldir2
-rw-r--r--tests/auto/qml/qqmlimport/tst_qqmlimport.cpp28
5 files changed, 43 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index e379d416fd..a31dbd1e08 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -1546,7 +1546,7 @@ bool QQmlImportsPrivate::addFileImport(const QString& uri, const QString &prefix
QString localFileOrQrc = QQmlFile::urlToLocalFileOrQrc(qmldirUrl);
Q_ASSERT(!localFileOrQrc.isEmpty());
- QString dir = QQmlFile::urlToLocalFileOrQrc(resolveLocalUrl(base, importUri));
+ const QString dir = localFileOrQrc.left(localFileOrQrc.lastIndexOf(Slash) + 1);
if (!typeLoader->directoryExists(dir)) {
if (!isImplicitImport) {
QQmlError error;
diff --git a/tests/auto/qml/qqmlimport/data/interceptQmldir.qml b/tests/auto/qml/qqmlimport/data/interceptQmldir.qml
new file mode 100644
index 0000000000..bf485b2282
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/interceptQmldir.qml
@@ -0,0 +1,7 @@
+import QtQml 2.2
+
+import "$(INTERCEPT)" as Intercepted
+
+QtObject {
+ property QtObject view: Intercepted.View {}
+}
diff --git a/tests/auto/qml/qqmlimport/data/intercepted/View.qml b/tests/auto/qml/qqmlimport/data/intercepted/View.qml
new file mode 100644
index 0000000000..92aa3af95a
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/intercepted/View.qml
@@ -0,0 +1,5 @@
+import QtQml 2.2
+
+QtObject {
+ property int foo: 12
+}
diff --git a/tests/auto/qml/qqmlimport/data/intercepted/qmldir b/tests/auto/qml/qqmlimport/data/intercepted/qmldir
new file mode 100644
index 0000000000..ab31de73d8
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/intercepted/qmldir
@@ -0,0 +1,2 @@
+module SomeModule
+View 1.0 View.qml
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
index 70aaa9678e..a3cb68fdcb 100644
--- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
+++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
@@ -28,6 +28,7 @@
#include <QtTest/QtTest>
#include <QQmlApplicationEngine>
+#include <QQmlAbstractUrlInterceptor>
#include <QtQuick/qquickview.h>
#include <QtQuick/qquickitem.h>
#include <private/qqmlimport_p.h>
@@ -43,6 +44,7 @@ private slots:
void uiFormatLoading();
void completeQmldirPaths_data();
void completeQmldirPaths();
+ void interceptQmldir();
void cleanup();
};
@@ -185,6 +187,32 @@ void tst_QQmlImport::completeQmldirPaths()
QCOMPARE(QQmlImports::completeQmldirPaths(uri, basePaths, majorVersion, minorVersion), expectedPaths);
}
+class QmldirUrlInterceptor : public QQmlAbstractUrlInterceptor {
+public:
+ QUrl intercept(const QUrl &url, DataType type) override
+ {
+ if (type != UrlString && !url.isEmpty() && url.isValid()) {
+ QString str = url.toString(QUrl::None);
+ return str.replace(QStringLiteral("$(INTERCEPT)"), QStringLiteral("intercepted"));
+ }
+ return url;
+ }
+};
+
+void tst_QQmlImport::interceptQmldir()
+{
+ QQmlEngine engine;
+ QmldirUrlInterceptor interceptor;
+ engine.setUrlInterceptor(&interceptor);
+
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("interceptQmldir.qml"));
+ QVERIFY(component.isReady());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+}
+
+
QTEST_MAIN(tst_QQmlImport)
#include "tst_qqmlimport.moc"