diff options
author | Andy Shaw <andy.shaw@qt.io> | 2018-11-28 14:56:45 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-11-30 14:47:36 +0000 |
commit | 2afe4a1a074096a3a6476aae21e732c418717da7 (patch) | |
tree | 816ff47677ddda7ecce26caa3f57b357668e0b68 | |
parent | 042707a6339cff6795d8d2ea08f927924f218a7b (diff) |
Android: Don't use blocking queued when suspending the application
If the application gets suspended when a blocking queued connection is
made then it will cause the application to hang when being resumed.
Therefore a check is needed to still post the event to the other thread
but in a non blocking manner so that it does not cause a hang on return.
Fixes: QTBUG-72101
Change-Id: I6d53c97ed6d9d500559da2a9fd195226d1fc9905
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
-rw-r--r-- | src/plugins/platforms/android/qandroidinputcontext.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index c5cd0b92d9..7b3546f9bb 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -99,9 +99,13 @@ static jfieldID m_selectionStartFieldID = 0; static jfieldID m_startOffsetFieldID = 0; static jfieldID m_textFieldID = 0; +Q_DECLARE_METATYPE(std::function<void()>) + static void runOnQtThread(const std::function<void()> &func) { - QMetaObject::invokeMethod(m_androidInputContext, "safeCall", Qt::BlockingQueuedConnection, Q_ARG(std::function<void()>, func)); + const bool block = QGuiApplication::applicationState() >= Qt::ApplicationInactive; + QMetaObject::invokeMethod(m_androidInputContext, "safeCall", + block ? Qt::BlockingQueuedConnection : Qt::QueuedConnection, Q_ARG(std::function<void()>, func)); } static jboolean beginBatchEdit(JNIEnv */*env*/, jobject /*thiz*/) @@ -512,6 +516,7 @@ QAndroidInputContext::QAndroidInputContext() m_handleMode = Hidden; updateSelectionHandles(); }); + qRegisterMetaType<std::function<void()>>(); } QAndroidInputContext::~QAndroidInputContext() |