diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 4d0ce966970..6ffaef8f7c9 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -566,6 +566,17 @@ static QString normalizePath(QString ret) return QDir::fromNativeSeparators(ret); }; +static bool keepQtBuildDefaults() +{ +#if QT_CONFIG(settings) + QSettings *config = QLibraryInfoPrivate::configuration(); + Q_ASSERT(config != nullptr); + return config->value("Config/MergeQtConf", false).toBool(); +#else + return false; +#endif +} + #if QT_CONFIG(settings) static QVariant libraryPathToValue(QLibraryInfo::LibraryPath loc) { @@ -575,21 +586,26 @@ static QVariant libraryPathToValue(QLibraryInfo::LibraryPath loc) return value; QSettings *config = QLibraryInfoPrivate::configuration(); Q_ASSERT(config != nullptr); + // if keepQtBuildDefaults returns true, + // we only consider explicit values listed in qt.conf + QVariant defaultValue = keepQtBuildDefaults() + ? QVariant() + : QVariant(li.defaultValue); config->beginGroup("Paths"_L1); auto cleanup = qScopeGuard([&]() { config->endGroup(); }); if (li.fallbackKey.isNull()) { - value = config->value(li.key, li.defaultValue); + value = config->value(li.key, defaultValue); } else { value = config->value(li.key); if (!value.isValid()) - value = config->value(li.fallbackKey, li.defaultValue); + value = config->value(li.fallbackKey, defaultValue); } return value; } #endif // settings QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, - QLibraryInfoPrivate::UsageMode usageMode) + UsageMode usageMode) { const QLibraryInfo::LibraryPath loc = p; QList ret; @@ -611,7 +627,7 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p, } #endif // settings - if (!fromConf) { + if (!fromConf || keepQtBuildDefaults()) { QString noConfResult; if (loc == QLibraryInfo::PrefixPath) { noConfResult = getPrefix(usageMode); diff --git a/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt b/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt index 33198dd3f04..d72e871967e 100644 --- a/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt +++ b/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt @@ -20,4 +20,5 @@ qt_add_resources(tst_qlibraryinfo "qtconffiles" empty.qt.conf partial.qt.conf list.qt.conf + merge.qt.conf ) diff --git a/tests/auto/corelib/global/qlibraryinfo/merge.qt.conf b/tests/auto/corelib/global/qlibraryinfo/merge.qt.conf new file mode 100644 index 00000000000..a687dc4d718 --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/merge.qt.conf @@ -0,0 +1,5 @@ +[Paths] +QmlImports = "/path/to/myqml" + +[Config] +MergeQtConf=true diff --git a/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp b/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp index 63b5cddcb02..b7d79c05f57 100644 --- a/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp +++ b/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp @@ -16,6 +16,7 @@ private slots: void path_data(); void path(); void paths(); + void merge(); }; void tst_QLibraryInfo::initTestCase() @@ -80,6 +81,23 @@ void tst_QLibraryInfo::paths() QCOMPARE(values[2], baseDir + "/relativePath"); } +void tst_QLibraryInfo::merge() +{ + QString qtConfPath(u":/merge.qt.conf"); + QLibraryInfoPrivate::setQtconfManualPath(&qtConfPath); + QLibraryInfoPrivate::reload(); + + QString baseDir = QCoreApplication::applicationDirPath(); + QString docPath = QLibraryInfo::path(QLibraryInfo::DocumentationPath); + // we can't know where exactly the doc path points, but it should not point to ${baseDir}/doc, + // which would be the behavior without merge_qt_conf + QCOMPARE_NE(docPath, baseDir + "/doc"); + + QList values = QLibraryInfo::paths(QLibraryInfo::QmlImportsPath); + QCOMPARE(values.size(), 2); // custom entry + Qt default entry + QCOMPARE(values[0], "/path/to/myqml"); +} + QTEST_GUILESS_MAIN(tst_QLibraryInfo) #include "tst_qlibraryinfo.moc"