diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h
index 3ee0eaaa61b698b3317af33bdc13c2664f9dd97c..8b58fdf55f2935c65d5b38c90c359f1d0e134ca9 100644
--- a/src/corelib/kernel/qcoreevent.h
+++ b/src/corelib/kernel/qcoreevent.h
@@ -323,6 +323,7 @@ private:
     friend class QGraphicsViewPrivate;
     friend class QGraphicsScene;
     friend class QGraphicsScenePrivate;
+    friend class QWidgetWindow;
 #ifndef QT_NO_GESTURES
     friend class QGestureManager;
 #endif
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index 0031d8e965edcab3c738c7c4b05edcf3494cbb05..fc328e7af0f6588c0bf3591b8446aba19bd347d5 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -440,11 +440,13 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
                     if (!win)
                         win = w->nativeParentWidget()->windowHandle();
                     if (win && win->geometry().contains(event->globalPos())) {
+                        // Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec()
                         const QPoint localPos = win->mapFromGlobal(event->globalPos());
-                        QMouseEvent e(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
-                        QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event));
-                        e.setTimestamp(event->timestamp());
-                        QApplication::sendSpontaneousEvent(win, &e);
+                        QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
+                        e->spont = 1;
+                        QGuiApplicationPrivate::setMouseEventSource(e, QGuiApplicationPrivate::mouseEventSource(event));
+                        e->setTimestamp(event->timestamp());
+                        QCoreApplication::postEvent(win, e);
                     }
                 }
             }