Prefer QT_PLUGIN_PATH over compiled-in paths.

Currently, when one compiles a Qt plugin that is also installed
system wide to a local path added to QT_PLUGIN_PATH, you have no
way to ever load it as the global plugin will always be preferred.
This is due to the order in which the QCoreApplications::libraryPaths
are constructed, which always appended the QT_PLUGIN_PATH contents
to the end.

Now, the QT_PLUGIN_PATH contents are put first, such that the plugins
in there are preferred and loaded.

[ChangeLog][QtCore][QPluginLoader] Fixed the search order of Qt plugins
so that paths specified by the QT_PLUGIN_PATH environment variable
are searched before built-in paths.

Change-Id: Iad8ca2cd34e7a622c191a416c01c1c5cc1812fc9
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Milian Wolff 2015-07-27 11:49:55 +02:00
parent dc3dd4f634
commit 6129be8a4b

View File

@ -2541,17 +2541,6 @@ QStringList QCoreApplication::libraryPaths()
if (!coreappdata()->app_libpaths) { if (!coreappdata()->app_libpaths) {
QStringList *app_libpaths = coreappdata()->app_libpaths = new QStringList; QStringList *app_libpaths = coreappdata()->app_libpaths = new QStringList;
QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath);
if (QFile::exists(installPathPlugins)) {
// Make sure we convert from backslashes to slashes.
installPathPlugins = QDir(installPathPlugins).canonicalPath();
if (!app_libpaths->contains(installPathPlugins))
app_libpaths->append(installPathPlugins);
}
// If QCoreApplication is not yet instantiated,
// make sure we add the application path when we construct the QCoreApplication
if (self) self->d_func()->appendApplicationPathToLibraryPaths();
const QByteArray libPathEnv = qgetenv("QT_PLUGIN_PATH"); const QByteArray libPathEnv = qgetenv("QT_PLUGIN_PATH");
if (!libPathEnv.isEmpty()) { if (!libPathEnv.isEmpty()) {
@ -2564,6 +2553,18 @@ QStringList QCoreApplication::libraryPaths()
} }
} }
} }
QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath);
if (QFile::exists(installPathPlugins)) {
// Make sure we convert from backslashes to slashes.
installPathPlugins = QDir(installPathPlugins).canonicalPath();
if (!app_libpaths->contains(installPathPlugins))
app_libpaths->append(installPathPlugins);
}
// If QCoreApplication is not yet instantiated,
// make sure we add the application path when we construct the QCoreApplication
if (self) self->d_func()->appendApplicationPathToLibraryPaths();
} }
return *(coreappdata()->app_libpaths); return *(coreappdata()->app_libpaths);
} }