From 60f07671e1770c4f6fd71bbad7cf88ca35ab4de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 9 Sep 2024 19:46:49 +0200 Subject: [PATCH] Android: Return QAndroidApplication instance via nativeInterface() getter The QAndroidApplication native interface wrongly uses static methods instead of virtual functions, which has lead to client call sites not using the preferred QCoreApplication::nativeInterface() API to resolve the interface, and a lack of an implementation in QCoreApplication for the resolveInterface function. We now implement resolveInterface for Android, so that the interface can be resolved via QCoreApplication::nativeInterface(), even if the interface itself (for now) is based on static methods. Task-number: QTBUG-128796 Pick-to: 6.8 Change-Id: Id4d8b9a6fcc7d0e2cc76de07dc0742dc5917f3ca Reviewed-by: Assam Boudjelthia --- src/corelib/kernel/qcoreapplication.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 2f3ca871d5e..e804e738854 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #if QT_CONFIG(permissions) #include @@ -3361,6 +3362,16 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc void *QCoreApplication::resolveInterface(const char *name, int revision) const { +#if defined(Q_OS_ANDROID) + // The QAndroidApplication is wrongly using static methods for + // its native interface (QTBUG-128796). Until we fix that we at + // least want the preferred way of resolving a native interface + // to work, so provide a minimal subclass of the interface. + using namespace QNativeInterface; + struct AndroidApplication : public QAndroidApplication {}; + static AndroidApplication androidApplication; + QT_NATIVE_INTERFACE_RETURN_IF(QAndroidApplication, &androidApplication); +#endif Q_UNUSED(name); Q_UNUSED(revision); return nullptr; }