QCompleter: add more nullptr checks for the widget
The widget might become nullptr, especially after delivering events to it. So consistently test for nullptr before calling the event function. Fixes: QTBUG-128478 Pick-to: 6.5 Change-Id: Ieed4e8b68b41488fafd9946d718c1d77fad39a44 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 6b86d9d08b407a56bad2d37f65169e36356b0741) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
8c40e8cf12
commit
92005e34e8
@ -1370,11 +1370,13 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the event to the widget. If the widget accepted the event, do nothing
|
if (d->widget) {
|
||||||
// If the widget did not accept the event, provide a default implementation
|
// Send the event to the widget. If the widget accepted the event, do nothing
|
||||||
d->eatFocusOut = false;
|
// If the widget did not accept the event, provide a default implementation
|
||||||
(static_cast<QObject *>(d->widget))->event(ke);
|
d->eatFocusOut = false;
|
||||||
d->eatFocusOut = true;
|
(static_cast<QObject *>(d->widget))->event(ke);
|
||||||
|
d->eatFocusOut = true;
|
||||||
|
}
|
||||||
if (!d->widget || e->isAccepted() || !d->popup->isVisible()) {
|
if (!d->widget || e->isAccepted() || !d->popup->isVisible()) {
|
||||||
// widget lost focus, hide the popup
|
// widget lost focus, hide the popup
|
||||||
if (d->widget && (!d->widget->hasFocus()
|
if (d->widget && (!d->widget->hasFocus()
|
||||||
@ -1426,8 +1428,9 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
|
|||||||
|
|
||||||
#ifdef QT_KEYPAD_NAVIGATION
|
#ifdef QT_KEYPAD_NAVIGATION
|
||||||
case QEvent::KeyRelease: {
|
case QEvent::KeyRelease: {
|
||||||
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
|
if (d->widget &&
|
||||||
if (QApplicationPrivate::keypadNavigationEnabled() && ke->key() == Qt::Key_Back) {
|
QApplicationPrivate::keypadNavigationEnabled() && ke->key() == Qt::Key_Back) {
|
||||||
|
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
|
||||||
// Send the event to the 'widget'. This is what we did for KeyPress, so we need
|
// Send the event to the 'widget'. This is what we did for KeyPress, so we need
|
||||||
// to do the same for KeyRelease, in case the widget's KeyPress event set
|
// to do the same for KeyRelease, in case the widget's KeyPress event set
|
||||||
// up something (such as a timer) that is relying on also receiving the
|
// up something (such as a timer) that is relying on also receiving the
|
||||||
@ -1444,7 +1447,8 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
|
|||||||
|
|
||||||
case QEvent::MouseButtonPress: {
|
case QEvent::MouseButtonPress: {
|
||||||
#ifdef QT_KEYPAD_NAVIGATION
|
#ifdef QT_KEYPAD_NAVIGATION
|
||||||
if (QApplicationPrivate::keypadNavigationEnabled()) {
|
if (d->widget
|
||||||
|
&& QApplicationPrivate::keypadNavigationEnabled()) {
|
||||||
// if we've clicked in the widget (or its descendant), let it handle the click
|
// if we've clicked in the widget (or its descendant), let it handle the click
|
||||||
QWidget *source = qobject_cast<QWidget *>(o);
|
QWidget *source = qobject_cast<QWidget *>(o);
|
||||||
if (source) {
|
if (source) {
|
||||||
@ -1473,7 +1477,8 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e)
|
|||||||
return true;
|
return true;
|
||||||
case QEvent::InputMethod:
|
case QEvent::InputMethod:
|
||||||
case QEvent::ShortcutOverride:
|
case QEvent::ShortcutOverride:
|
||||||
QCoreApplication::sendEvent(d->widget, e);
|
if (d->widget)
|
||||||
|
QCoreApplication::sendEvent(d->widget, e);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user