diff options
Diffstat (limited to 'src/qml/qml/qqmlimport.cpp')
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index f51fc6dc22..2eb756be1f 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -1397,6 +1397,18 @@ QTypeRevision QQmlImportsPrivate::addFileImport( const QString& uri, const QString &prefix, QTypeRevision version, uint flags, QQmlImportDatabase *database, QList<QQmlError> *errors) { + if (uri.startsWith(Slash) || uri.startsWith(Colon)) { + QQmlError error; + const QString fix = uri.startsWith(Slash) ? QLatin1String("file:") + uri + : QLatin1String("qrc") + uri; + error.setDescription(QQmlImportDatabase::tr( + "\"%1\" is not a valid import URL. " + "You can pass relative paths or URLs with schema, but not " + "absolute paths or resource paths. Try \"%2\".").arg(uri, fix)); + errors->prepend(error); + return QTypeRevision(); + } + Q_ASSERT(errors); QQmlImportNamespace *nameSpace = importNamespace(prefix); @@ -1670,7 +1682,7 @@ void QQmlImports::setDesignerSupportRequired(bool b) designerSupportRequired = b; } -static QStringList parseEnvImportPath(const QString &envImportPath) +static QStringList parseEnvPath(const QString &envImportPath) { if (QDir::listSeparator() == u':') { // Double colons are interpreted as separator + resource path. @@ -1710,7 +1722,7 @@ QQmlImportDatabase::QQmlImportDatabase(QQmlEngine *e) auto addEnvImportPath = [this](const char *var) { if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty(var))) { - const QStringList paths = parseEnvImportPath(qEnvironmentVariable(var)); + const QStringList paths = parseEnvPath(qEnvironmentVariable(var)); for (int ii = paths.count() - 1; ii >= 0; --ii) addImportPath(paths.at(ii)); } @@ -1722,15 +1734,19 @@ QQmlImportDatabase::QQmlImportDatabase(QQmlEngine *e) addImportPath(QStringLiteral("qrc:/qt-project.org/imports")); addImportPath(QCoreApplication::applicationDirPath()); + + auto addEnvPluginPath = [this](const char *var) { + if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty(var))) { + const QStringList paths = parseEnvPath(qEnvironmentVariable(var)); + for (int ii = paths.count() - 1; ii >= 0; --ii) + addPluginPath(paths.at(ii)); + } + }; + + addEnvPluginPath("QML_PLUGIN_PATH"); #if defined(Q_OS_ANDROID) addImportPath(QStringLiteral("qrc:/android_rcc_bundle/qml")); - if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QT_BUNDLED_LIBS_PATH"))) { - const QString envImportPath = qEnvironmentVariable("QT_BUNDLED_LIBS_PATH"); - QLatin1Char pathSep(':'); - QStringList paths = envImportPath.split(pathSep, Qt::SkipEmptyParts); - for (int ii = paths.count() - 1; ii >= 0; --ii) - addPluginPath(paths.at(ii)); - } + addEnvPluginPath("QT_BUNDLED_LIBS_PATH"); #elif defined(Q_OS_MACOS) // Add the main bundle's Resources/qml directory as an import path, so that QML modules are // found successfully when running the app from its build dir. |