OSDN Git Service

smart QGuiPlatformPlugin instance caching
authorIvailo Monev <xakepa10@gmail.com>
Tue, 22 Aug 2023 05:27:11 +0000 (12:27 +0700)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 22 Aug 2023 05:27:11 +0000 (12:27 +0700)
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>
src/gui/kernel/qguiplatformplugin.cpp

index 6ec624b..de3cddc 100644 (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;
 }