diff options
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 8 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 5 | ||||
-rw-r--r-- | tests/auto/qml/qrcqml/data/imports/QrcImport/Imported.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qrcqml/data/imports/QrcImport/qmldir | 1 | ||||
-rw-r--r-- | tests/auto/qml/qrcqml/data/importtest.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qrcqml/qrcqml.qrc | 38 | ||||
-rw-r--r-- | tests/auto/qml/qrcqml/tst_qrcqml.cpp | 31 |
8 files changed, 79 insertions, 19 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 580aaf4899..f9b261b314 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1610,7 +1610,13 @@ void QQmlEnginePrivate::dereferenceScarceResources() /*! Adds \a path as a directory where the engine searches for installed modules in a URL-based directory structure. - The \a path may be a local filesystem directory or a URL. + + The \a path may be a local filesystem directory, a + \l {The Qt Resource System}{Qt Resource} path (\c {:/imports}), a + \l {The Qt Resource System}{Qt Resource} url (\c {qrc:/imports}) or a URL. + + The \a path will be converted into canonical form before it + is added to the import path list. The newly added \a path will be first in the importPathList(). diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 55c07ac35a..20da154673 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -1536,6 +1536,11 @@ void QQmlImportDatabase::addImportPath(const QString& path) if (url.scheme() == QLatin1String("file")) { cPath = QQmlFile::urlToLocalFileOrQrc(url); + } else if (path.startsWith(QLatin1Char(':'))) { + // qrc directory, e.g. :/foo + // need to convert to a qrc url, e.g. qrc:/foo + cPath = QStringLiteral("qrc") + path; + cPath.replace(Backslash, Slash); } else if (url.isRelative() || (url.scheme().length() == 1 && QFile::exists(path)) ) { // windows path QDir dir = QDir(path); diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 1d7070675b..c66cd283da 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -1633,6 +1633,11 @@ QString QQmlTypeLoader::absoluteFilePath(const QString &path) // qrc resource QFileInfo fileInfo(path); return fileInfo.isFile() ? fileInfo.absoluteFilePath() : QString(); + } else if (path.count() > 3 && path.at(3) == QLatin1Char(':') && + path.startsWith(QLatin1String("qrc"), Qt::CaseInsensitive)) { + // qrc resource url + QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(path)); + return fileInfo.isFile() ? fileInfo.absoluteFilePath() : QString(); } int lastSlash = path.lastIndexOf(QLatin1Char('/')); QStringRef dirPath(&path, 0, lastSlash); diff --git a/tests/auto/qml/qrcqml/data/imports/QrcImport/Imported.qml b/tests/auto/qml/qrcqml/data/imports/QrcImport/Imported.qml new file mode 100644 index 0000000000..c2ef0a6906 --- /dev/null +++ b/tests/auto/qml/qrcqml/data/imports/QrcImport/Imported.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Item { + property string tokenProperty: "bar" +} diff --git a/tests/auto/qml/qrcqml/data/imports/QrcImport/qmldir b/tests/auto/qml/qrcqml/data/imports/QrcImport/qmldir new file mode 100644 index 0000000000..8eb1fa5c18 --- /dev/null +++ b/tests/auto/qml/qrcqml/data/imports/QrcImport/qmldir @@ -0,0 +1 @@ +Imported 1.0 Imported.qml diff --git a/tests/auto/qml/qrcqml/data/importtest.qml b/tests/auto/qml/qrcqml/data/importtest.qml new file mode 100644 index 0000000000..dd45bd8b98 --- /dev/null +++ b/tests/auto/qml/qrcqml/data/importtest.qml @@ -0,0 +1,5 @@ +import QrcImport 1.0 + +Imported { + tokenProperty: "foo" +} diff --git a/tests/auto/qml/qrcqml/qrcqml.qrc b/tests/auto/qml/qrcqml/qrcqml.qrc index 4ee303a1ee..9ab0565366 100644 --- a/tests/auto/qml/qrcqml/qrcqml.qrc +++ b/tests/auto/qml/qrcqml/qrcqml.qrc @@ -1,19 +1,21 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource> - <file>data/main.qml</file> - <file>data/SameDir.qml</file> - <file>data/SubDir.qml</file> -</qresource> -<qresource> - <!-- unspecified prefix seems to mean '/' --> - <file alias="main.qml">data/main2.qml</file> - <file alias="SameDir.qml">data/SameDir2.qml</file> -</qresource> -<qresource prefix="/search"> - <file alias="main.qml">data/main3.qml</file> - <file alias="SameDir.qml">data/SameDir3.qml</file> -</qresource> -<qresource prefix="/search/data"> - <file alias="SubDir.qml">data/SubDir.qml</file> -</qresource> +<RCC> + <qresource prefix="/"> + <file>data/main.qml</file> + <file>data/SameDir.qml</file> + <file>data/SubDir.qml</file> + <file alias="main.qml">data/main2.qml</file> + <file alias="SameDir.qml">data/SameDir2.qml</file> + <file alias="importtest.qml">data/importtest.qml</file> + </qresource> + <qresource prefix="/search"> + <file alias="main.qml">data/main3.qml</file> + <file alias="SameDir.qml">data/SameDir3.qml</file> + </qresource> + <qresource prefix="/search/data"> + <file alias="SubDir.qml">data/SubDir.qml</file> + </qresource> + <qresource prefix="/imports"> + <file alias="QrcImport/Imported.qml">data/imports/QrcImport/Imported.qml</file> + <file alias="QrcImport/qmldir">data/imports/QrcImport/qmldir</file> + </qresource> </RCC> diff --git a/tests/auto/qml/qrcqml/tst_qrcqml.cpp b/tests/auto/qml/qrcqml/tst_qrcqml.cpp index a09c908069..37a7e7860f 100644 --- a/tests/auto/qml/qrcqml/tst_qrcqml.cpp +++ b/tests/auto/qml/qrcqml/tst_qrcqml.cpp @@ -57,6 +57,8 @@ public: private slots: void basicLoad_data(); void basicLoad(); + void qrcImport_data(); + void qrcImport(); }; tst_qrcqml::tst_qrcqml() @@ -101,6 +103,35 @@ void tst_qrcqml::basicLoad() delete o; } +void tst_qrcqml::qrcImport_data() +{ + QTest::addColumn<QString>("importPath"); + QTest::addColumn<QString>("token"); + + QTest::newRow("qrc path") + << ":/imports" + << "foo"; + + QTest::newRow("qrc url") + << "qrc:/imports" + << "foo"; +} + +void tst_qrcqml::qrcImport() +{ + QFETCH(QString, importPath); + QFETCH(QString, token); + + QQmlEngine e; + e.addImportPath(importPath); + QQmlComponent c(&e, QUrl("qrc:///importtest.qml")); + QVERIFY(c.isReady()); + QObject *o = c.create(); + QVERIFY(o); + QCOMPARE(o->property("tokenProperty").toString(), token); + delete o; +} + QTEST_MAIN(tst_qrcqml) #include "tst_qrcqml.moc" |