Skip to content

Commit

Permalink
Avoid better sending events to null objects
Browse files Browse the repository at this point in the history
Qml TextInput element was able to cause crash by having selection on
focus out. That (incorrectly) causes update() to trigger. Better
to be more careful on input context side.

RevBy: Michael Hasselmann
  • Loading branch information
pvuorela committed Sep 23, 2013
1 parent dbc0403 commit 17fdf86
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions input-context/minputcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ void MInputContext::commit()

QInputMethodEvent event("", attributes);
event.setCommitString(preedit);
QGuiApplication::sendEvent(qGuiApp->focusObject(), &event);
if (qGuiApp->focusObject()) {
QGuiApplication::sendEvent(qGuiApp->focusObject(), &event);
}

preedit.clear();
preeditCursorPos = -1;
Expand Down Expand Up @@ -447,12 +449,16 @@ void MInputContext::commitString(const QString &string, int replacementStart,
attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, start, 0, QVariant());
QInputMethodEvent event("", attributes);
event.setCommitString(string, replacementStart, replacementLength);
QGuiApplication::sendEvent(qGuiApp->focusObject(), &event);
if (qGuiApp->focusObject()) {
QGuiApplication::sendEvent(qGuiApp->focusObject(), &event);
}

} else {
QInputMethodEvent event;
event.setCommitString(string, replacementStart, replacementLength);
QGuiApplication::sendEvent(qGuiApp->focusObject(), &event);
if (qGuiApp->focusObject()) {
QGuiApplication::sendEvent(qGuiApp->focusObject(), &event);
}
}

if (hadPreedit) {
Expand Down Expand Up @@ -683,7 +689,7 @@ QMap<QString, QVariant> MInputContext::getStateInformation() const

stateInformation["focusState"] = inputMethodAccepted();

if (!inputMethodAccepted()) {
if (!inputMethodAccepted() || !qGuiApp->focusObject()) {
return stateInformation;
}

Expand Down

0 comments on commit 17fdf86

Please sign in to comment.