diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qnsview_complextext.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview_complextext.mm | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index 5926840cf3..28f6817a51 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -63,7 +63,7 @@ - (void)unmarkText { if (!m_composingText.isEmpty()) { - if (QObject *fo = m_platformWindow->window()->focusObject()) { + if (QObject *fo = self.focusObject) { QInputMethodQueryEvent queryEvent(Qt::ImEnabled); if (QCoreApplication::sendEvent(fo, &queryEvent)) { if (queryEvent.value(Qt::ImEnabled).toBool()) { @@ -82,6 +82,17 @@ @implementation QNSView (ComplexText) +- (QObject*)focusObject +{ + // The text input system may still hold a reference to our QNSView, + // even after QCocoaWindow has been destructed, delivering text input + // events to us, so we need to guard for this situation explicitly. + if (!m_platformWindow) + return nullptr; + + return m_platformWindow->window()->focusObject(); +} + - (void)insertNewline:(id)sender { Q_UNUSED(sender); @@ -110,7 +121,7 @@ commitString = QString::fromCFString(reinterpret_cast<CFStringRef>(aString)); }; } - if (QObject *fo = m_platformWindow->window()->focusObject()) { + if (QObject *fo = self.focusObject) { QInputMethodQueryEvent queryEvent(Qt::ImEnabled); if (QCoreApplication::sendEvent(fo, &queryEvent)) { if (queryEvent.value(Qt::ImEnabled).toBool()) { @@ -178,7 +189,7 @@ m_composingText = preeditString; - if (QObject *fo = m_platformWindow->window()->focusObject()) { + if (QObject *fo = self.focusObject) { m_composingFocusObject = fo; QInputMethodQueryEvent queryEvent(Qt::ImEnabled); if (QCoreApplication::sendEvent(fo, &queryEvent)) { @@ -200,7 +211,7 @@ - (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange { Q_UNUSED(actualRange) - QObject *fo = m_platformWindow->window()->focusObject(); + QObject *fo = self.focusObject; if (!fo) return nil; QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImCurrentSelection); @@ -235,7 +246,7 @@ { NSRange selectedRange = {0, 0}; - QObject *fo = m_platformWindow->window()->focusObject(); + QObject *fo = self.focusObject; if (!fo) return selectedRange; QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImCurrentSelection); @@ -258,7 +269,7 @@ Q_UNUSED(aRange) Q_UNUSED(actualRange) - QObject *fo = m_platformWindow->window()->focusObject(); + QObject *fo = self.focusObject; if (!fo) return NSZeroRect; |