smart QGuiPlatformPlugin instance caching

once QCoreApplication/QApplication instance is created the environment
lookup stops, this trick can be applied to other environment variable
checks

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-22 12:27:11 +07:00
parent 48f864a5f4
commit 3a767e2043

View file

@ -46,6 +46,11 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, platformLoader, (QString::fromLatin1("
*/
QGuiPlatformPlugin *qt_guiPlatformPlugin()
{
static QGuiPlatformPlugin *appplugin = nullptr;
if (appplugin) {
return appplugin;
}
QGuiPlatformPlugin *plugin = nullptr;
#ifndef QT_NO_LIBRARY
static const char* platformEnvTbl[] = {
@ -72,6 +77,10 @@ QGuiPlatformPlugin *qt_guiPlatformPlugin()
plugin = &def;
}
if (qApp) {
appplugin = plugin;
}
return plugin;
}