From 4d6fd8302eb2e0d79e6c193a3a616d782b0e20c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinja=20Paavosepp=C3=A4?= Date: Thu, 13 Jun 2024 12:35:53 +0300 Subject: [PATCH] Android: Check input delegate for null when QtView attached to window If the Qt libs have not been loaded before the QtView is attached to the window, it leads to accessing the input delegate, which only gets initialized after the creation of the libs, so we get a null pointer expection. Add a null check, and a boolean to make sure we update the input delegate with the view once the libraries are loaded and the input delegate has been created. Task-number: QTBUG-126177 Change-Id: I7372596884c7d0ed6c9cca812b46399ecfb74367 Reviewed-by: Assam Boudjelthia (cherry picked from commit dc62ddd1521a5754aec0031ade17743da3ed0585) Reviewed-by: Qt Cherry-pick Bot --- .../org/qtproject/qt/android/QtEmbeddedDelegate.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java index 5298ac02bdf..7559d5078d9 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java @@ -105,6 +105,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase BackendRegister.unregisterBackend(QtMenuInterface.class); BackendRegister.unregisterBackend(QtLayoutInterface.class); } + updateInputDelegate(); } } @@ -168,11 +169,14 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase // QtEmbeddedViewInterface implementation end private void updateInputDelegate() { - if (m_view == null) { - m_inputDelegate.setEditPopupMenu(null); + // If the QtView has attached to the window before Qt libs have been loaded, + // the input delegate will be null + if (m_inputDelegate == null) return; - } - m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_view)); + if (m_view == null) + m_inputDelegate.setEditPopupMenu(null); + else + m_inputDelegate.setEditPopupMenu(new EditPopupMenu(m_activity, m_view)); } private void createRootWindow() {