diff options
author | Shawn Rutledge <[email protected]> | 2025-01-20 10:20:48 +0100 |
---|---|---|
committer | Shawn Rutledge <[email protected]> | 2025-01-20 20:45:59 +0100 |
commit | 1accd2421686b387daa115b3a46974fce0fdb118 (patch) | |
tree | 735b81161f106b07a8204803ea4c9f947a918e88 /src/widgets/kernel/qwidgetwindow.cpp | |
parent | 6404714183b3fcf93ac27482c5a3193a4f93767d (diff) |
Avoid dangling d-pointer deref in QWidgetWindow::handleMouseEvent
If you drag-and-drop a OpenGLWidget in Designer, the main window gets
re-created when the OpenGLWidget is instantiated. So in general (in
rare cases), at the end of QWidgetWindow::handleMouseEvent() we might
have a different window, and therefore can't reliably call
QWindowPrivate::maybeSynthesizeContextMenuEvent() without checking for
a valid pointer.
Amends 84a5f50c7766c99f62b22bb4388137e0aa8dd13d
Pick-to: 6.9
Fixes: QTBUG-132912
Change-Id: I7b220b4daceab988aadabf9427ef6b2d5624e00d
Reviewed-by: Friedemann Kleint <[email protected]>
Diffstat (limited to 'src/widgets/kernel/qwidgetwindow.cpp')
-rw-r--r-- | src/widgets/kernel/qwidgetwindow.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 0565835e38b..53bf13a5735 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -506,6 +506,11 @@ void QWidgetWindow::handleNonClientAreaMouseEvent(QMouseEvent *e) void QWidgetWindow::handleMouseEvent(QMouseEvent *event) { Q_D(QWidgetWindow); + + // Event delivery can potentially result in window re-creation (QTBUG-132912) + // so we need QPointer to avoid a dangling d below + QPointer<QWidgetWindow> self = this; + if (auto *activePopupWidget = QApplication::activePopupWidget()) { QPointF mapped = event->position(); if (activePopupWidget != m_widget) @@ -666,6 +671,9 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) event->setAccepted(translated.isAccepted()); } + if (self.isNull()) + return; + #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) if ( #else |