diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-05-25 15:27:38 (GMT) |
---|---|---|
committer | Samuli Piippo <samuli.piippo@digia.com> | 2011-06-09 10:06:00 (GMT) |
commit | 46028848c063488bc64af7ed0dabd1c89fc09593 (patch) | |
tree | 963f32d94dcd0e68233746108eb0c94e5faef1c8 | |
parent | c0a100d137841b25898b08bb20c20030b174b991 (diff) | |
download | Qt-46028848c063488bc64af7ed0dabd1c89fc09593.zip Qt-46028848c063488bc64af7ed0dabd1c89fc09593.tar.gz Qt-46028848c063488bc64af7ed0dabd1c89fc09593.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
(cherry picked from commit a32c96e753c2f5a123e518a92762ec9c9ff3b0b7)
-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 f4874b1..cf62a8a 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -5212,18 +5212,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 580c3c8..88dcac5 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -306,6 +306,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) @@ -314,6 +316,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; |