Skip to content

Commit

Permalink
fix QApplciation with a QML popupWindow
Browse files Browse the repository at this point in the history
Since 6.8, QML has popupWindow. When in popupModeMode,
it does not necessarily have a popupWidget.

Not checking whether popWidget is nullptr will cause the
program to crash.

Fixes: QTBUG-131664
Pick-to: 6.8
Change-Id: I624b62ef7185f0ab35215c2c34b0d6e9c80539a0
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
tsic404 committed Nov 29, 2024
1 parent b3c0b08 commit 706d54e
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/widgets/kernel/qwidgetwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ void QWidgetWindow::handleNonClientAreaMouseEvent(QMouseEvent *e)

void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
if (QApplicationPrivate::inPopupMode()) {
QPointer<QWidget> activePopupWidget = QApplication::activePopupWidget();
if (auto *activePopupWidget = QApplication::activePopupWidget()) {
QPointF mapped = event->position();
if (activePopupWidget != m_widget)
mapped = activePopupWidget->mapFromGlobal(event->globalPosition());
Expand Down Expand Up @@ -682,7 +681,7 @@ void QWidgetWindow::handleTouchEvent(QTouchEvent *event)
if (event->type() == QEvent::TouchCancel) {
QApplicationPrivate::translateTouchCancel(event->pointingDevice(), event->timestamp());
event->accept();
} else if (QApplicationPrivate::inPopupMode()) {
} else if (QApplication::activePopupWidget()) {
// Ignore touch events for popups. This will cause QGuiApplication to synthesise mouse
// events instead, which QWidgetWindow::handleMouseEvent will forward correctly:
event->ignore();
Expand All @@ -697,8 +696,7 @@ void QWidgetWindow::handleKeyEvent(QKeyEvent *event)
return;

QObject *receiver = QWidget::keyboardGrabber();
if (!receiver && QApplicationPrivate::inPopupMode()) {
QWidget *popup = QApplication::activePopupWidget();
if (auto *popup = QApplication::activePopupWidget(); !receiver && popup) {
QWidget *popupFocusWidget = popup->focusWidget();
receiver = popupFocusWidget ? popupFocusWidget : popup;
}
Expand Down Expand Up @@ -1151,8 +1149,7 @@ void QWidgetWindow::handleGestureEvent(QNativeGestureEvent *e)
{
// copy-pasted code to find correct widget follows:
QObject *receiver = nullptr;
if (QApplicationPrivate::inPopupMode()) {
QWidget *popup = QApplication::activePopupWidget();
if (auto *popup = QApplication::activePopupWidget()) {
QWidget *popupFocusWidget = popup->focusWidget();
receiver = popupFocusWidget ? popupFocusWidget : popup;
}
Expand Down

0 comments on commit 706d54e

Please sign in to comment.