mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 10:22:55 +00:00
do not cache the QGuiPlatformPlugin instance from qt_guiPlatformPlugin()
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>
This commit is contained in:
parent
0140df36db
commit
0d219c845c
1 changed files with 20 additions and 21 deletions
|
@ -46,33 +46,32 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, platformLoader, (QString::fromLatin1("
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue