diff --git a/examples/widgets/mainwindows/mdi/mdi.pro b/examples/widgets/mainwindows/mdi/mdi.pro
index 2e3c232..6c03693 100644
--- a/examples/widgets/mainwindows/mdi/mdi.pro
+++ b/examples/widgets/mainwindows/mdi/mdi.pro
@@ -6,7 +6,7 @@ SOURCES       = main.cpp \
                 mainwindow.cpp \
                 mdichild.cpp
 RESOURCES     = mdi.qrc
-
+CONFIG+=console
 # install
 target.path = $$[QT_INSTALL_EXAMPLES]/widgets/mainwindows/mdi
 INSTALLS += target
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 40e9b97..7a1c2fe 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -1573,6 +1573,7 @@ bool QWindow::setKeyboardGrabEnabled(bool grab)
     Q_D(QWindow);
     if (grab && QGuiApplicationPrivate::noGrab)
         return false;
+    qDebug() << __FUNCTION__ << this << grab;
     if (d->platformWindow)
         return d->platformWindow->setKeyboardGrabEnabled(grab);
     return false;
@@ -1590,6 +1591,7 @@ bool QWindow::setKeyboardGrabEnabled(bool grab)
 bool QWindow::setMouseGrabEnabled(bool grab)
 {
     Q_D(QWindow);
+    qDebug() << __FUNCTION__ << this << grab << "plw" << d->platformWindow;
     if (grab && QGuiApplicationPrivate::noGrab)
         return false;
     if (d->platformWindow)
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 0b983e7..e12569d 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2462,6 +2462,10 @@ QWidget *QApplicationPrivate::pickMouseReceiver(QWidget *candidate, const QPoint
                                                 Qt::MouseButtons buttons, QWidget *buttonDown,
                                                 QWidget *alienWidget)
 {
+    qDebug() << __FUNCTION__
+             << "buttons" <<buttons
+             << "candidate" << candidate << "buttonDown" << buttonDown
+             << "alienWidget" << alienWidget;
     Q_ASSERT(candidate);
 
     QWidget *mouseGrabber = QWidget::mouseGrabber();
@@ -2475,16 +2479,20 @@ QWidget *QApplicationPrivate::pickMouseReceiver(QWidget *candidate, const QPoint
 
     QWidget *receiver = candidate;
 
-    if (!mouseGrabber)
+    if (!mouseGrabber) {
         mouseGrabber = (buttonDown && !isBlockedByModal(buttonDown)) ? buttonDown : alienWidget;
+        qDebug() <<  __FUNCTION__ << "if (!mouseGrabber): " << mouseGrabber;
+    }
 
     if (mouseGrabber && mouseGrabber != candidate) {
         receiver = mouseGrabber;
+        qDebug() <<  __FUNCTION__ << "Assigning mouseGrabber: " << receiver;
         *pos = receiver->mapFromGlobal(candidate->mapToGlobal(windowPos));
 #ifdef ALIEN_DEBUG
         qDebug() << "  ** receiver adjusted to:" << receiver << "pos:" << pos;
 #endif
     }
+    qDebug() << __FUNCTION__ <<  "candidate"  << candidate << "returns receiver" << receiver;
 
     return receiver;
 
@@ -2787,6 +2795,7 @@ bool QApplicationPrivate::shouldQuit()
 
 static inline void closeAllPopups()
 {
+    qDebug() << __FUNCTION__ ;
     // Close all popups: In case some popup refuses to close,
     // we give up after 1024 attempts (to avoid an infinite loop).
     int maxiter = 1024;
@@ -2913,6 +2922,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e)
     case QEvent::ApplicationDeactivate:
         // Close all popups (triggers when switching applications
         // by pressing ALT-TAB on Windows, which is not receive as key event.
+        qDebug() << __FUNCTION__ << "Deactivate";
         closeAllPopups();
         break;
     case QEvent::Wheel: // User input and window activation makes tooltips sleep
diff --git a/src/widgets/kernel/qapplication_qpa.cpp b/src/widgets/kernel/qapplication_qpa.cpp
index 5893c52..8d9a891 100644
--- a/src/widgets/kernel/qapplication_qpa.cpp
+++ b/src/widgets/kernel/qapplication_qpa.cpp
@@ -171,6 +171,7 @@ static void grabForPopup(QWidget *popup)
 {
     Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created));
     popupGrabOk = qt_widget_private(popup)->stealKeyboardGrab(true);
+    qDebug() << __FUNCTION__ << popup << "popupGrabOk"<< popupGrabOk;
     if (popupGrabOk) {
         popupGrabOk = qt_widget_private(popup)->stealMouseGrab(true);
         if (!popupGrabOk) {
@@ -182,6 +183,7 @@ static void grabForPopup(QWidget *popup)
 
 void QApplicationPrivate::closePopup(QWidget *popup)
 {
+    qDebug() << __FUNCTION__ << popup;
     if (!popupWidgets)
         return;
     popupWidgets->removeAll(popup);
@@ -239,11 +241,15 @@ void QApplicationPrivate::closePopup(QWidget *popup)
 
 void QApplicationPrivate::openPopup(QWidget *popup)
 {
+    qDebug() <<__FUNCTION__ << popup;
     openPopupCount++;
     if (!popupWidgets) // create list
         popupWidgets = new QWidgetList;
     popupWidgets->append(popup); // add to end of list
 
+    qDebug() <<__FUNCTION__ << popup << "count"
+    <<           QApplicationPrivate::popupWidgets->count();
+
     if (QApplicationPrivate::popupWidgets->count() == 1) // grab mouse/keyboard
         grabForPopup(popup);
 
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 65e435f..a178a97 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -2220,8 +2220,10 @@ void QWidgetPrivate::deactivateWidgetCleanup()
     if (QApplication::activeWindow() == q)
         QApplication::setActiveWindow(0);
     // If the is the active mouse press widget, reset it
-    if (q == qt_button_down)
+    if (q == qt_button_down) {
+        qDebug() << __FUNCTION__ << "clearing qt_button_down" << qt_button_down;
         qt_button_down = 0;
+    }
 }
 
 
diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp
index 17ed4ca..04bb423 100644
--- a/src/widgets/kernel/qwidget_qpa.cpp
+++ b/src/widgets/kernel/qwidget_qpa.cpp
@@ -410,6 +410,7 @@ void QWidget::grabMouse()
 
     if (QWindow *window = grabberWindow(this))
         window->setMouseGrabEnabled(true);
+    qDebug() << __FUNCTION__ << this;
 
     qt_mouseGrb = this;
     qt_pressGrab = 0;
@@ -428,12 +429,16 @@ bool QWidgetPrivate::stealMouseGrab(bool grab)
     // This is like a combination of grab/releaseMouse() but with error checking
     // and it has no effect on the result of mouseGrabber().
     Q_Q(QWidget);
+    qDebug() << __FUNCTION__ << q << grab;
+    if (q->objectName()== QLatin1String("EditMenu"))
+        qDebug("EditMenu grabs!");
     QWindow *window = grabberWindow(q);
     return window ? window->setMouseGrabEnabled(grab) : false;
 }
 
 void QWidget::releaseMouse()
 {
+    qDebug() << __FUNCTION__ << this ;
     if (qt_mouseGrb == this) {
         if (QWindow *window = grabberWindow(this))
             window->setMouseGrabEnabled(false);
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index fc328e7..20246d8 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -361,6 +361,8 @@ void QWidgetWindow::handleNonClientAreaMouseEvent(QMouseEvent *e)
 
 void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
 {
+    if (event->type() != QEvent::MouseMove)
+        qDebug() << __FUNCTION__ << this <<event;
     static const QEvent::Type contextMenuTrigger =
         QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ?
         QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
@@ -483,12 +485,14 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
     if (!widget)
         widget = m_widget;
 
-    if (event->type() == QEvent::MouseButtonPress)
+
+    if (event->type() == QEvent::MouseButtonPress) {
         qt_button_down = widget;
+        qDebug() << __FUNCTION__ << "Assigning qt_button_down" << widget;
+    }
 
     QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(),
                                                                qt_button_down, widget);
-
     if (!receiver) {
         if (event->type() == QEvent::MouseButtonRelease)
             QApplicationPrivate::mouse_buttons &= ~event->button();
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 7e48bad..59d565a 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -445,6 +445,7 @@ void QMenuPrivate::hideUpToMenuBar()
         while(caused) {
 #ifndef QT_NO_MENUBAR
             if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) {
+                qDebug() << __FUNCTION__ << "Clearing menubar";
                 mb->d_func()->setCurrentAction(0);
                 mb->d_func()->setKeyboardMode(false);
                 caused = 0;
@@ -1883,6 +1884,7 @@ QSize QMenu::sizeHint() const
 */
 void QMenu::popup(const QPoint &p, QAction *atAction)
 {
+    qDebug() << '>' << __FUNCTION__ << this << p << atAction;
     Q_D(QMenu);
     if (d->scroll) { // reset scroll state from last popup
         if (d->scroll->scrollOffset)
@@ -2114,6 +2116,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
     QAccessibleEvent event(this, QAccessible::PopupMenuStart);
     QAccessible::updateAccessibility(&event);
 #endif
+    qDebug() << '<' << __FUNCTION__;
 }
 
 /*!
@@ -2238,8 +2241,10 @@ void QMenu::hideEvent(QHideEvent *)
     QAccessible::updateAccessibility(&event);
 #endif
 #ifndef QT_NO_MENUBAR
-    if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget))
+    if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) {
+        qDebug() << __FUNCTION__ << "Clearing menubar";
         mb->d_func()->setCurrentAction(0);
+    }
 #endif
     d->mouseDown = 0;
     d->hasHadMouse = false;
@@ -2759,6 +2764,7 @@ void QMenu::keyPressEvent(QKeyEvent *e)
             d->hideMenu(this); // hide after getting causedPopup
 #ifndef QT_NO_MENUBAR
             if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) {
+                qDebug() << __FUNCTION__ << "setting menubar" << d->menuAction;
                 mb->d_func()->setCurrentAction(d->menuAction);
                 mb->d_func()->setKeyboardMode(true);
             }
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp
index f523ac2..f19ba8e 100644
--- a/src/widgets/widgets/qmenubar.cpp
+++ b/src/widgets/widgets/qmenubar.cpp
@@ -44,6 +44,8 @@
 #include <qstyle.h>
 #include <qlayout.h>
 #include <qapplication.h>
+#include <qaction.h>
+#include <qdebug.h>
 #include <qdesktopwidget.h>
 #ifndef QT_NO_ACCESSIBILITY
 # include <qaccessible.h>
@@ -274,8 +276,10 @@ void QMenuBarPrivate::focusFirstAction()
         updateGeometries();
         int index = 0;
         while (index < actions.count() && actionRects.at(index).isNull()) ++index;
-        if (index < actions.count())
+        if (index < actions.count()) {
+            qDebug() << __FUNCTION__ << "set"<<index << actions.at(index);
             setCurrentAction(actions.at(index));
+        }
     }
 }
 
@@ -308,10 +312,15 @@ void QMenuBarPrivate::setKeyboardMode(bool b)
 void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst)
 {
     Q_Q(QMenuBar);
-    if(!action || !action->menu() || closePopupMode)
+    qDebug() << __FUNCTION__ << action << "activateFirst=" << activateFirst << ")closePopupMode=" << closePopupMode;
+    if(!action || !action->menu() || closePopupMode) {
+        qDebug() << __FUNCTION__ << "return" << action << "closePopupMode" << closePopupMode;
         return;
+    }
+    qDebug() << __FUNCTION__ << "popupState = true";
     popupState = true;
     if (action->isEnabled() && action->menu()->isEnabled()) {
+        qDebug() << __FUNCTION__ << "Clearing closePopupMode";
         closePopupMode = 0;
         activeMenu = action->menu();
         activeMenu->d_func()->causedPopup.widget = q;
@@ -350,6 +359,7 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst)
 
         if(!defaultPopDown || (fitUp && !fitDown))
             pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y()));
+        qDebug() << __FUNCTION__ << "activeMenu" << activeMenu << pos;
         activeMenu->popup(pos);
         if(activateFirst)
             activeMenu->d_func()->setFirstActionActive();
@@ -359,6 +369,13 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst)
 
 void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activateFirst)
 {
+    qDebug() << __FUNCTION__ << action << "popup" << popup << "activateFirst" << activateFirst;
+    if (action && action->objectName()==QLatin1String("EditMenuAction")) {
+        if (popup)
+            qDebug("POPPING up EditMenuAction");
+        else
+            qDebug("NOT POPPING up EditMenuAction");
+    }
     if(currentAction == action && popup == popupState)
         return;
 
@@ -379,6 +396,7 @@ void QMenuBarPrivate::setCurrentAction(QAction *action, bool popup, bool activat
     if(currentAction)
         q->update(actionRect(currentAction));
 
+    qDebug() << __FUNCTION__ << "popupState = " << popup;
     popupState = popup;
 #ifndef QT_NO_STATUSTIP
     QAction *previousAction = currentAction;
@@ -901,6 +919,7 @@ QAction *QMenuBar::activeAction() const
 void QMenuBar::setActiveAction(QAction *act)
 {
     Q_D(QMenuBar);
+    qDebug() << __FUNCTION__ << "set"<<act;
     d->setCurrentAction(act, true, false);
 }
 
@@ -1032,12 +1051,17 @@ void QMenuBar::setVisible(bool visible)
 void QMenuBar::mousePressEvent(QMouseEvent *e)
 {
     Q_D(QMenuBar);
-    if(e->button() != Qt::LeftButton)
+    if(e->button() != Qt::LeftButton) {
+        qDebug() << __FUNCTION__ << "other button";
         return;
+    }
 
     d->mouseDown = true;
 
     QAction *action = d->actionAt(e->pos());
+    qDebug() << __FUNCTION__ << e << "action" << action
+             << "curAction" << d->currentAction << "d->popupState" << d->popupState ;
+
     if (!action || !d->isVisible(action) || !action->isEnabled()) {
         d->setCurrentAction(0);
 #ifndef QT_NO_WHATSTHIS
@@ -1048,12 +1072,16 @@ void QMenuBar::mousePressEvent(QMouseEvent *e)
     }
 
     if(d->currentAction == action && d->popupState) {
+        qDebug() << __FUNCTION__ << "Checking whether to set closePopupMode"
+                 << action << "popupState=" << d->popupState <<  "activeMenu" << d->activeMenu;
         if(QMenu *menu = d->activeMenu) {
             d->activeMenu = 0;
             menu->hide();
+            qDebug() << __FUNCTION__ << "hide activeMenu Setting closePopupMode";
             d->closePopupMode = 1;
         }
     } else {
+        qDebug() << __FUNCTION__ << "setCurrentAction" << action << "leaving closePopupMode= "<< d->closePopupMode;
         d->setCurrentAction(action, true);
     }
 }
@@ -1069,13 +1097,18 @@ void QMenuBar::mouseReleaseEvent(QMouseEvent *e)
 
     d->mouseDown = false;
     QAction *action = d->actionAt(e->pos());
+    qDebug() << __FUNCTION__ << action << "d->currentAction" << d->currentAction
+             << "d->closePopupMode" << d->closePopupMode;
+
     if((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) {
         //we set the current action before activating
         //so that we let the leave event set the current back to 0
+        qDebug() << __FUNCTION__ << "setCurrentAction" << action;
         d->setCurrentAction(action, false);
         if(action)
             d->activateAction(action, QAction::Trigger);
     }
+    qDebug() << __FUNCTION__ << "Clearing closePopupMode";
     d->closePopupMode = 0;
 }
 
@@ -1193,9 +1226,14 @@ void QMenuBar::mouseMoveEvent(QMouseEvent *e)
     if (!(e->buttons() & Qt::LeftButton))
         d->mouseDown = false;
     bool popupState = d->popupState || d->mouseDown;
+
     QAction *action = d->actionAt(e->pos());
-    if ((action && d->isVisible(action)) || !popupState)
+    if ((action && d->isVisible(action)) || !popupState) {
+        qDebug() << __FUNCTION__ <<e
+                 << "d->popupState" << d->popupState << "d->mouseDown" << d->mouseDown
+                 << "calling setCurrentAction" << action << "popupState" << popupState;
         d->setCurrentAction(action, popupState);
+    }
 }
 
 /*!
@@ -1308,9 +1346,10 @@ void QMenuBar::focusInEvent(QFocusEvent *)
 /*!
   \reimp
 */
-void QMenuBar::focusOutEvent(QFocusEvent *)
+void QMenuBar::focusOutEvent(QFocusEvent *f)
 {
     Q_D(QMenuBar);
+    qDebug() << __FUNCTION__ << f;
     if(!d->popupState) {
         d->setCurrentAction(0);
         d->setKeyboardMode(false);
@@ -1324,6 +1363,7 @@ void QMenuBar::timerEvent (QTimerEvent *e)
 {
     Q_D(QMenuBar);
     if (e->timerId() == d->autoReleaseTimer.timerId()) {
+        qDebug() << __FUNCTION__ ;
         d->autoReleaseTimer.stop();
         d->setCurrentAction(0);
     }
