Skip to content

Commit

Permalink
Android: Create QtWindow layout and set parent in the calling thread
Browse files Browse the repository at this point in the history
In the QtWindow constructor, creation of the layout and setting
the parent window were posted on the Android UI thread, leading
to them being called at a later point. If QAndroidPlatformWindow
did not have a parent at the point it was created in, but
setParent() was called shortly after, the QtWindow.setParent()
call with the actual intended parent got invoked before the
Runnable posted in the constructor got ran, leading to the
parent being overwritten with the null one passed to the
constructor, essentially leaving the QtWindow as a top level
one, while the QAndroidPlatformWindow was a child window.

The above would happen more often with foreign child windows,
sometimes causing hang ups when the parent of the foreign
child window was shown.

Creating the QtLayout outside of the Android UI thread seems
to be safe, as long as we only modify its view hierarchy inside
it.

Task-number: QTBUG-116187
Change-Id: If1ed1983f5d6ba56e625148ee6a61771234a2aa1
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 8df46c8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
  • Loading branch information
Tinja Paavoseppä authored and Qt Cherry-pick Bot committed Jan 30, 2024
1 parent a114fd5 commit 4f6cbed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/android/jar/src/org/qtproject/qt/android/QtWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class QtWindow implements QtSurfaceInterface, QtLayout.QtTouchListener {
public QtWindow(Context context, QtWindow parentWindow)
{
m_id = View.generateViewId();
m_layout = new QtLayout(context, this);
setParent(parentWindow);
QtNative.runAction(() -> {
m_layout = new QtLayout(context, this);
setParent(parentWindow);
m_gestureDetector =
new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent event) {
Expand Down

0 comments on commit 4f6cbed

Please sign in to comment.