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
Change-Id: Id4d8b9a6fcc7d0e2cc76de07dc0742dc5917f3ca
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 60f07671e1770c4f6fd71bbad7cf88ca35ab4de0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2024-09-09 19:46:49 +02:00 committed by Qt Cherry-pick Bot
parent 8f5b06f977
commit 4e66be84be

View File

@ -43,6 +43,7 @@
#include <private/qlocale_p.h> #include <private/qlocale_p.h>
#include <private/qlocking_p.h> #include <private/qlocking_p.h>
#include <private/qhooks_p.h> #include <private/qhooks_p.h>
#include <private/qnativeinterface_p.h>
#if QT_CONFIG(permissions) #if QT_CONFIG(permissions)
#include <private/qpermissions_p.h> #include <private/qpermissions_p.h>
@ -3406,6 +3407,16 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
void *QCoreApplication::resolveInterface(const char *name, int revision) const 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); Q_UNUSED(name); Q_UNUSED(revision);
return nullptr; return nullptr;
} }