diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-05-25 15:27:38 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-05-25 15:42:42 (GMT) |
commit | a32c96e753c2f5a123e518a92762ec9c9ff3b0b7 (patch) | |
tree | 7a32757a240f5172228903fa16883a6fcfd96a70 | |
parent | 132933df69b355695dd9401d81b7bc2ac5f5684f (diff) | |
download | Qt-a32c96e753c2f5a123e518a92762ec9c9ff3b0b7.zip Qt-a32c96e753c2f5a123e518a92762ec9c9ff3b0b7.tar.gz Qt-a32c96e753c2f5a123e518a92762ec9c9ff3b0b7.tar.bz2 |
Dont crash when assigning the same input context twice.
Added a guard check to return if the given input context is the same is we
already have.
Explicitly mention in the doc that we take ownership of the given input context
object.
Task-number: QTBUG-10780
Reviewed-by: Thomas Zander
-rw-r--r-- | src/gui/kernel/qapplication.cpp | 10 | ||||
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index b805a72..57c4c99 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -5270,18 +5270,20 @@ bool QApplication::keypadNavigationEnabled() This function replaces the QInputContext instance used by the application with \a inputContext. + Qt takes ownership of the given \a inputContext. + \sa inputContext() */ void QApplication::setInputContext(QInputContext *inputContext) { - Q_D(QApplication); - Q_UNUSED(d);// only static members being used. + if (inputContext == QApplicationPrivate::inputContext) + return; if (!inputContext) { qWarning("QApplication::setInputContext: called with 0 input context"); return; } - delete d->inputContext; - d->inputContext = inputContext; + delete QApplicationPrivate::inputContext; + QApplicationPrivate::inputContext = inputContext; } /*! diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 1c7f6ac..569af42 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -312,6 +312,8 @@ QInputContext *QWidget::inputContext() This function sets the input context \a context on this widget. + Qt takes ownership of the given input \a context. + \sa inputContext() */ void QWidget::setInputContext(QInputContext *context) @@ -320,6 +322,8 @@ void QWidget::setInputContext(QInputContext *context) if (!testAttribute(Qt::WA_InputMethodEnabled)) return; #ifndef QT_NO_IM + if (context == d->ic) + return; if (d->ic) delete d->ic; d->ic = context; |