diff options
author | Tinja Paavoseppä <tinja.paavoseppa@qt.io> | 2023-12-08 11:24:43 +0200 |
---|---|---|
committer | Tinja Paavoseppä <tinja.paavoseppa@qt.io> | 2023-12-08 15:53:37 +0200 |
commit | 2bc7d38bd63843c4598ed501e3adbf0e39162c61 (patch) | |
tree | d3d9ffb035add93e032661095e2ec399b8da3526 /src/plugins/platforms/android/qandroidplatformwindow.cpp | |
parent | 6ff88f97a6d24d1098583421161f8f903f9dafde (diff) |
Android: Make QtWindow wrap the QtLayout instead of inherit it
The layout is a ViewGroup, and should be created in the Android UI
thread, while for ease of use on C++ side we should be able to
construct the Java object in the platform window constructor to
avoid later calls not having a valid object reference. Trying to
make a blocking call to Android thread from Qt thread can lead to
dead locks, so move only the creation of the layout itself into
Android thread, making the QtWindow a wrapper for it, which we can
immediately return to C++/Qt thread. Most of the calls made to
QtWindow are anyway already passed to the Android UI thread.
As a drive by, add a missing QtNative.runAction() to
bringChildToFront().
Change-Id: Ib2495ddda8267384656557cbe40be5da869f82c3
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/android/qandroidplatformwindow.cpp')
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformwindow.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformwindow.cpp b/src/plugins/platforms/android/qandroidplatformwindow.cpp index 9a633e97af..84a4eab389 100644 --- a/src/plugins/platforms/android/qandroidplatformwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformwindow.cpp @@ -51,12 +51,10 @@ QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window) if (parent()) m_nativeParentQtWindow = static_cast<QAndroidPlatformWindow*>(parent())->nativeWindow(); - QNativeInterface::QAndroidApplication::runOnAndroidMainThread([this]() { - m_nativeQtWindow = QJniObject::construct<QtJniTypes::QtWindow>( - QNativeInterface::QAndroidApplication::context(), - m_nativeParentQtWindow); - m_nativeViewId = m_nativeQtWindow.callMethod<jint>("getId"); - }).waitForFinished(); + m_nativeQtWindow = QJniObject::construct<QtJniTypes::QtWindow>( + QNativeInterface::QAndroidApplication::context(), + m_nativeParentQtWindow); + m_nativeViewId = m_nativeQtWindow.callMethod<jint>("getId"); if (window->isTopLevel()) platformScreen()->addWindow(this); |