diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-06-06 13:17:37 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-06-09 00:08:36 +0200 |
commit | f0049873d2ce0742a2df7ce265db70ca8baa8442 (patch) | |
tree | e7feb2737dca6851cc9a32101be10335d3f201a7 /src/widgets/widgets/qmenu.cpp | |
parent | e84c0df50f51c61aa49b47823582b0f8de406e3d (diff) |
QMenu: don't crash when nested tear-off menus are closed
QMenu's causedStack maintains a list of menus on the way to the menu,
and might contain nullptr if one of the entries was a tear-off menu
that got closed (and thus destroyed, due to DeleteOnClose).
If the entry we get from the stack is nullptr, fall back to the passed-
in parent widget pointer, and test for nullptr before accessing.
Add a test case that crashes without the fix.
Fixes: QTBUG-112217
Pick-to: 6.6 6.5 6.2
Change-Id: I958182db47c3cc8733e1780f7efef43881ffae11
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/widgets/widgets/qmenu.cpp')
-rw-r--r-- | src/widgets/widgets/qmenu.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 987dce71d9..ea984305eb 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -93,7 +93,9 @@ public: Q_D(QTornOffMenu); // make the torn-off menu a sibling of p (instead of a child) QWidget *parentWidget = d->causedStack.isEmpty() ? p : d->causedStack.constLast(); - if (parentWidget->parentWidget()) + if (!parentWidget && p) + parentWidget = p; + if (parentWidget && parentWidget->parentWidget()) parentWidget = parentWidget->parentWidget(); setParent(parentWidget, Qt::Window | Qt::Tool); setAttribute(Qt::WA_DeleteOnClose, true); |