summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-12-06 12:47:58 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-12-08 15:14:17 +0100
commitc95de359b4fe7bc03f7defdb057ebbe79c51b3dd (patch)
tree57a3372a971b0892dc9fd1be2596aa2154312838 /src/widgets/widgets/qcombobox.cpp
parent57a4c0d73c3521a0855ce597204b096928c43117 (diff)
QComboBox: Don't dereference potential nullptr, simplify
Amends a874087504cf5af8bb4171d4137f23f100b7063b, which tested whether d->container is nullptr to decide whether to hide the popup, and then dereferences d->container later without checking again. This raised a correct static analyzer warning. Simplify that logic. hidePopup() does nothing if there is no visible container, and we don't want to accept() the cancel key if there isn't. So the closeOnCancel logic isn't actually needed, we only need to accept the ShortcutOverride to make sure that QComboBox sees the Cancel key even if there is a shortcut registered, and then we can handle and accept the cancel key to call hidePopup() only if the popup is visible. Add test to verify that this interaction works as expected. Pick-to: 6.4 Task-number: QTBUG-108908 Change-Id: I60d92b068f0f5139d629cf4a58e225512170df77 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 5889545b1c..8b02f7c494 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -727,8 +727,7 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
return true;
default:
#if QT_CONFIG(shortcut)
- if (keyEvent->matches(QKeySequence::Cancel)) {
- closeOnCancel = true;
+ if (keyEvent->matches(QKeySequence::Cancel) && isVisible()) {
keyEvent->accept();
return true;
}
@@ -776,7 +775,6 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
void QComboBoxPrivateContainer::showEvent(QShowEvent *)
{
- closeOnCancel = true;
combo->update();
}
@@ -3218,10 +3216,9 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
break;
#endif
default:
- if (e->matches(QKeySequence::Cancel) && (!d->container || d->container->closeOnCancel)) {
+ if (d->container && d->container->isVisible() && e->matches(QKeySequence::Cancel)) {
hidePopup();
e->accept();
- d->container->closeOnCancel = false;
}
if (!d->lineEdit) {