From bcbbafca8828760e4c5d7d6c6ec689223ac908e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pasi=20Pet=C3=A4j=C3=A4j=C3=A4rvi?= Date: Wed, 23 Aug 2023 10:42:51 +0300 Subject: [PATCH] QGuiApplication: Report default platform name before initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling this function before we had a QGuiApplication instance, would return an empty string, even if QT_QPA_DEFAULT_PLATFORM_NAME was defined at compile time. We now return the default platform name [ChangeLog][QtGui][QGuiApplication] QGuiApplication::platformName now reports the default platform name if QGuiApplication hasn't been instantiated yet. It used to return an empty string. Change-Id: Iffe7cde8943ed2d186bc494d0920b9cf79389dd0 Reviewed-by: Tor Arne Vestbø Reviewed-by: Volker Hilsheimer (cherry picked from commit dd3840a1a201318c8f089dc7d34ec38f64e05b4e) Reviewed-by: Qt Cherry-pick Bot --- src/gui/kernel/qguiapplication.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 9d32a85a00c..60e9e499264 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1194,14 +1194,26 @@ QWindow *QGuiApplication::topLevelAt(const QPoint &pos) \li \c xcb is a plugin for the X11 window system, used on some desktop Linux platforms. \endlist + \note Calling this function without a QGuiApplication will return the default + platform name, if available. The default platform name is not affected by the + \c{-platform} command line option, or the \c QT_QPA_PLATFORM environment variable. + For more information about the platform plugins for embedded Linux devices, see \l{Qt for Embedded Linux}. */ QString QGuiApplication::platformName() { - return QGuiApplicationPrivate::platform_name ? - *QGuiApplicationPrivate::platform_name : QString(); + if (!QGuiApplication::instance()) { +#ifdef QT_QPA_DEFAULT_PLATFORM_NAME + return QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME); +#else + return QString(); +#endif + } else { + return QGuiApplicationPrivate::platform_name ? + *QGuiApplicationPrivate::platform_name : QString(); + } } Q_LOGGING_CATEGORY(lcQpaPluginLoading, "qt.qpa.plugin");