From 02bab22fde5de84c62e3eb86fde03248851d11dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinja=20Paavosepp=C3=A4?= Date: Wed, 27 Mar 2024 15:43:43 +0200 Subject: [PATCH] Android/QtView: Move resizing of the QWindow to Qt thread Since any window resize events originating from Qt side are ran in the Qt thread, having the one originating from Android run in the Android thread can lead to race conditions especially during orientation changes. Pick-to: 6.7 Change-Id: Iebebec2fffdaf9181b01fc1e8f539c7bc232996d Reviewed-by: Assam Boudjelthia --- .../platforms/android/androidwindowembedding.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/android/androidwindowembedding.cpp b/src/plugins/platforms/android/androidwindowembedding.cpp index 20021283c5..230776f571 100644 --- a/src/plugins/platforms/android/androidwindowembedding.cpp +++ b/src/plugins/platforms/android/androidwindowembedding.cpp @@ -49,11 +49,13 @@ namespace QtAndroidWindowEmbedding { void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint x, jint y, jint width, jint height) { - QWindow *window = reinterpret_cast(windowRef); - QWindow *parent = window->parent(); - if (parent) - parent->setGeometry(x, y, width, height); - window->setGeometry(0, 0, width, height); + QMetaObject::invokeMethod(qApp, [windowRef, x, y, width, height] { + QWindow *window = reinterpret_cast(windowRef); + QWindow *parent = window->parent(); + if (parent) + parent->setGeometry(x, y, width, height); + window->setGeometry(0, 0, width, height); + }); } bool registerNatives(QJniEnvironment& env) {