Android: Initialize window in QPlatformWindow::initialize() override

During the QAndroidPlatformWindow constructor we can't safely call
virtual functions of QPlatformWindow and expect them to resolve to
subclasses, e.g. QAndroidPlatformForeignWindow. Importantly, this
means we can't check isForeignWindow() during construction.

QPlatformWindow has a dedicated initialization function for this
use-case, so use that instead.

The existing order of between QAndroidPlatformForeignWindow and
QAndroidPlatformWindow has been kept as is.

Change-Id: I2a08326fae6a3b079cd153c50a13794310ac3d74
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
(cherry picked from commit 7150c79d0ee10d6aca330e6a0862b0fbfec071fc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2024-07-04 11:59:38 +02:00 committed by Qt Cherry-pick Bot
parent 4c1a82e4cf
commit c45da998ad
4 changed files with 19 additions and 2 deletions

View File

@ -11,9 +11,16 @@
QT_BEGIN_NAMESPACE
QAndroidPlatformForeignWindow::QAndroidPlatformForeignWindow(QWindow *window, WId nativeHandle)
: QAndroidPlatformWindow(window), m_view(nullptr), m_nativeViewInserted(false)
: QAndroidPlatformWindow(window)
, m_view(reinterpret_cast<jobject>(nativeHandle))
, m_nativeViewInserted(false)
{
m_view = reinterpret_cast<jobject>(nativeHandle);
}
void QAndroidPlatformForeignWindow::initialize()
{
QAndroidPlatformWindow::initialize();
if (isEmbeddingContainer()) {
m_nativeViewId = m_view.callMethod<jint>("getId");
return;

View File

@ -16,6 +16,7 @@ class QAndroidPlatformForeignWindow : public QAndroidPlatformWindow
{
public:
explicit QAndroidPlatformForeignWindow(QWindow *window, WId nativeHandle);
void initialize() override;
~QAndroidPlatformForeignWindow();
void setGeometry(const QRect &rect) override;
void setVisible(bool visible) override;

View File

@ -25,6 +25,13 @@ QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window)
m_surfaceContainerType(SurfaceContainer::TextureView), m_nativeParentQtWindow(nullptr),
m_androidSurfaceObject(nullptr)
{
// Please add any initialization in the function below
}
void QAndroidPlatformWindow::initialize()
{
QWindow *window = QPlatformWindow::window();
m_windowFlags = Qt::Widget;
m_windowState = Qt::WindowNoState;
// the surfaceType is overwritten in QAndroidPlatformOpenGLWindow ctor so let's save

View File

@ -32,6 +32,8 @@ public:
};
explicit QAndroidPlatformWindow(QWindow *window);
void initialize() override;
~QAndroidPlatformWindow();
void lower() override;
void raise() override;