From 32f71db1bdcf93c8a03a9ef11ff4044479afa369 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 3 Dec 2013 13:55:20 +0100 Subject: [PATCH] iOS: fix crash when application quits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An application will sometimes crash if the keyboard is told to hide while the application is about to quit. This patch will ensure that we set m_qioswindow (and [UIView qwindow]) to 0 when the window is destroyed. We also check this pointer before telling QUIView to resign first responder when closing the keyboard. The latter will fix the crash. Task-number: QTBUG-35356 Change-Id: I934088beb7e877c5b33d96225cb215a8ffd4dbb2 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qioswindow.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index 43f36e32e0..7b217e0bdc 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -341,7 +341,8 @@ // Resigning first responed status means that the virtual keyboard was closed, or // some other view became first responder. In either case we clear the focus object to // avoid blinking cursors in line edits etc: - static_cast(QObjectPrivate::get(m_qioswindow->window()))->clearFocusObject(); + if (m_qioswindow) + static_cast(QObjectPrivate::get(m_qioswindow->window()))->clearFocusObject(); return [super resignFirstResponder]; } @@ -423,8 +424,10 @@ - (QWindow *)qwindow { - if ([self isKindOfClass:[QUIView class]]) - return static_cast(self)->m_qioswindow->window(); + if ([self isKindOfClass:[QUIView class]]) { + if (QIOSWindow *w = static_cast(self)->m_qioswindow) + return w->window(); + } return nil; } @@ -461,6 +464,7 @@ QIOSWindow::~QIOSWindow() // cancellation of all touch events. [m_view touchesCancelled:0 withEvent:0]; + m_view->m_qioswindow = 0; [m_view removeFromSuperview]; [m_view release]; }