diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index f6164213b0e..4b116c54b2e 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -601,10 +601,24 @@ static QVariant libraryPathToValue(QLibraryInfo::LibraryPath loc) } #endif // settings +// TODO: There apparently are paths that are both absolute and relative for QFileSystemEntry. +// In particular on windows. + +static bool pathIsRelative(const QString &path) +{ + using FromInternalPath = QFileSystemEntry::FromInternalPath; + return !path.startsWith(':'_L1) && QFileSystemEntry(path, FromInternalPath{}).isRelative(); +} + +static bool pathIsAbsolute(const QString &path) +{ + using FromInternalPath = QFileSystemEntry::FromInternalPath; + return path.startsWith(':'_L1) || QFileSystemEntry(path, FromInternalPath{}).isAbsolute(); +} + QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, UsageMode usageMode) { - using FromInternalPath = QFileSystemEntry::FromInternalPath; const QLibraryInfo::LibraryPath loc = p; QList ret; bool fromConf = false; @@ -621,8 +635,7 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, ret = QList({ std::move(value).toString()}); for (qsizetype i = 0, end = ret.size(); i < end; ++i) { ret[i] = normalizePath(ret[i]); - pathsAreAbsolute = pathsAreAbsolute - && QFileSystemEntry(ret[i], FromInternalPath{}).isAbsolute(); + pathsAreAbsolute = pathsAreAbsolute && pathIsAbsolute(ret[i]); } } } @@ -645,8 +658,7 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, #endif } if (!noConfResult.isEmpty()) { - pathsAreAbsolute = pathsAreAbsolute - && QFileSystemEntry(noConfResult, FromInternalPath{}).isAbsolute(); + pathsAreAbsolute = pathsAreAbsolute && pathIsAbsolute(noConfResult); ret.push_back(std::move(noConfResult)); } } @@ -661,7 +673,7 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, baseDir = QLibraryInfoPrivate::path(QLibraryInfo::PrefixPath, usageMode); } for (qsizetype i = 0, end = ret.size(); i < end; ++i) - if (QFileSystemEntry(ret[i], FromInternalPath{}).isRelative()) + if (pathIsRelative(ret[i])) ret[i] = QDir::cleanPath(baseDir + u'/' + std::move(ret[i])); return ret; } diff --git a/tests/auto/corelib/global/qlibraryinfo/list.qt.conf b/tests/auto/corelib/global/qlibraryinfo/list.qt.conf index 9271b414ca3..5e67de1c78f 100644 --- a/tests/auto/corelib/global/qlibraryinfo/list.qt.conf +++ b/tests/auto/corelib/global/qlibraryinfo/list.qt.conf @@ -1,2 +1,3 @@ [Paths] Documentation = "/path/to/mydoc","/path/to/anotherdoc","relativePath" +QmlImports = ":/a/resource/path", ":a/broken/path", "a/relative/path" diff --git a/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp b/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp index 1d5315d6266..f60fd70ba24 100644 --- a/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp +++ b/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp @@ -79,6 +79,12 @@ void tst_QLibraryInfo::paths() QCOMPARE(values[1], "/path/to/anotherdoc"); QString baseDir = QCoreApplication::applicationDirPath(); QCOMPARE(values[2], baseDir + "/relativePath"); + + const QStringList qmlImportPaths = QLibraryInfo::paths(QLibraryInfo::QmlImportsPath); + const QStringList expected = { + ":/a/resource/path", ":a/broken/path", baseDir + "/a/relative/path" + }; + QCOMPARE(qmlImportPaths, expected); } void tst_QLibraryInfo::merge()