diff options
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 28 | ||||
-rw-r--r-- | tests/auto/qml/qqmlimport/tst_qqmlimport.cpp | 29 |
2 files changed, 51 insertions, 6 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index a6a230090e..b1d304924d 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -1893,12 +1893,28 @@ QQmlImportDatabase::QQmlImportDatabase(QQmlEngine *e) // env import paths if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QML2_IMPORT_PATH"))) { const QString envImportPath = qEnvironmentVariable("QML2_IMPORT_PATH"); -#if defined(Q_OS_WIN) - QLatin1Char pathSep(';'); -#else - QLatin1Char pathSep(':'); -#endif - QStringList paths = envImportPath.split(pathSep, Qt::SkipEmptyParts); + const QChar pathSep = QDir::listSeparator(); + QStringList paths; + if (pathSep == u':') { + // Double colons are interpreted as separator + resource path. + paths = envImportPath.split(u':'); + bool wasEmpty = false; + for (auto it = paths.begin(); it != paths.end();) { + if (it->isEmpty()) { + wasEmpty = true; + it = paths.erase(it); + } else { + if (wasEmpty) { + it->prepend(u':'); + wasEmpty = false; + } + ++it; + } + } + } else { + paths = envImportPath.split(pathSep, Qt::SkipEmptyParts); + } + for (int ii = paths.count() - 1; ii >= 0; --ii) addImportPath(paths.at(ii)); } diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp index 0fdec44cdf..316c4cb168 100644 --- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp +++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include <QtCore/qscopeguard.h> #include <QtTest/QtTest> #include <QQmlApplicationEngine> #include <QQmlAbstractUrlInterceptor> @@ -52,6 +53,7 @@ private slots: void partialImportVersions(); void registerModuleImport(); void cleanup(); + void envResourceImportPath(); }; void tst_QQmlImport::cleanup() @@ -59,6 +61,33 @@ void tst_QQmlImport::cleanup() QQmlImports::setDesignerSupportRequired(false); } +void tst_QQmlImport::envResourceImportPath() +{ + const bool hadEnv = qEnvironmentVariableIsSet("QML2_IMPORT_PATH"); + const QByteArray oldEnv = hadEnv ? qgetenv("QML2_IMPORT_PATH") : QByteArray(); + auto guard = qScopeGuard([&] { + if (hadEnv) + qputenv("QML2_IMPORT_PATH", oldEnv); + else + qunsetenv("QML2_IMPORT_PATH"); + }); + + const QStringList envPaths({ + QLatin1String(":/some/resource"), + dataDirectory(), + QLatin1String(":/some/other/resource"), + directory() + }); + + qputenv("QML2_IMPORT_PATH", envPaths.join(QDir::listSeparator()).toUtf8()); + + QQmlImportDatabase importDb(nullptr); + const QStringList importPaths = importDb.importPathList(); + + for (const QString &path : envPaths) + QVERIFY((importPaths.contains(path.startsWith(u':') ? QLatin1String("qrc") + path : path))); +} + void tst_QQmlImport::testDesignerSupported() { QQuickView *window = new QQuickView(); |