plugin lookup is affected by several things including environment variables
(QT_PLUGIN_PATH, QT_PLATFORM_PLUGIN, XDG_CURRENT_DESKTOP and
DESKTOP_SESSION which can be changed at any time by a setenv() call) and
plugin paths (QT_PLUGIN_PATH, QCoreApplication::pluginPaths() and the
related QCoreApplication methods to change the plugin paths during runtime)
so caching an instance of the plugin while beneficial is subject to not
being able to load a plugin that may be available only after environment
variable or plugin paths change
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
*/
QGuiPlatformPlugin *qt_guiPlatformPlugin()
{
- static QGuiPlatformPlugin *plugin = nullptr;
- if (!plugin) {
+ QGuiPlatformPlugin *plugin = nullptr;
#ifndef QT_NO_LIBRARY
- static const char* platformEnvTbl[] = {
- "QT_PLATFORM_PLUGIN",
- "XDG_CURRENT_DESKTOP",
- "DESKTOP_SESSION",
- nullptr
- };
- int counter = 0;
- while (platformEnvTbl[counter]) {
- QString key = qGetEnv(platformEnvTbl[counter]);
- if (!key.isEmpty()) {
- plugin = qobject_cast<QGuiPlatformPlugin*>(platformLoader()->instance(key));
- if (plugin) {
- break;
- }
+ static const char* platformEnvTbl[] = {
+ "QT_PLATFORM_PLUGIN",
+ "XDG_CURRENT_DESKTOP",
+ "DESKTOP_SESSION",
+ nullptr
+ };
+ int counter = 0;
+ while (platformEnvTbl[counter]) {
+ QString key = qGetEnv(platformEnvTbl[counter]);
+ if (!key.isEmpty()) {
+ plugin = qobject_cast<QGuiPlatformPlugin*>(platformLoader()->instance(key));
+ if (plugin) {
+ break;
}
- counter++;
}
+ counter++;
+ }
#endif // QT_NO_LIBRARY
- if (!plugin) {
- static QGuiPlatformPlugin def;
- plugin = &def;
- }
+ if (!plugin) {
+ static QGuiPlatformPlugin def;
+ plugin = &def;
}
+
return plugin;
}