diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index 276d73a..7ab713f 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -1674,6 +1674,7 @@ extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wPa
         if (qt_win_ignoreNextMouseReleaseEvent) {
             qt_win_ignoreNextMouseReleaseEvent = false;
             if (qt_button_down && qt_button_down->internalWinId() == autoCaptureWnd) {
+                qDebug() << __FUNCTION__ << "calling releaseAutoCapture";
                 releaseAutoCapture();
                 qt_button_down = 0;
             }
@@ -2180,8 +2181,10 @@ extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wPa
                         widget->hideChildren(true);
                     }
                 }
-                if  (!wParam && autoCaptureWnd == widget->internalWinId())
+                if  (!wParam && autoCaptureWnd == widget->internalWinId()) {
+                    qDebug() << __FUNCTION__ << "calling releaseAutoCapture";
                     releaseAutoCapture();
+                }
                 result = false;
                 break;
 
@@ -2729,6 +2732,7 @@ void QApplicationPrivate::enterModal_sys(QWidget *widget)
     if (!qt_modal_stack)
         qt_modal_stack = new QWidgetList;
 
+    qDebug() << __FUNCTION__ << "calling releaseAutoCapture";
     releaseAutoCapture();
     ClipCursor(0);
     QWidget *leave = qt_last_mouse_receiver;
@@ -2859,6 +2863,7 @@ void QApplicationPrivate::openPopup(QWidget *popup)
 
     if (QApplicationPrivate::popupWidgets->count() == 1 && !qt_nograb()) {
         Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created));
+        qDebug() << __FUNCTION__ << "Calling setAutoCapture" << popup;
         setAutoCapture(popup->internalWinId());        // grab mouse/keyboard
     }
     // Popups are not focus-handled by the window system (the first
@@ -2893,8 +2898,10 @@ void QApplicationPrivate::closePopup(QWidget *popup)
                                 && !popup->testAttribute(Qt::WA_NoMouseReplay));
         if (!popup->isEnabled())
             return;
-        if (!qt_nograb())                        // grabbing not disabled
+        if (!qt_nograb())  {                       // grabbing not disabled
+            qDebug() << __FUNCTION__ << "calling releaseAutoCapture";
             releaseAutoCapture();
+        }
         QWidget *fw = QApplicationPrivate::active_window ? QApplicationPrivate::active_window->focusWidget()
             : QApplication::focusWidget();
         if (fw) {
@@ -2913,6 +2920,7 @@ void QApplicationPrivate::closePopup(QWidget *popup)
         QWidget* aw = QApplicationPrivate::popupWidgets->last();
         if (QApplicationPrivate::popupWidgets->count() == 1) {
             Q_ASSERT(aw->testAttribute(Qt::WA_WState_Created));
+            qDebug() << __FUNCTION__ << "Calling setAutoCapture" << aw;
             setAutoCapture(aw->internalWinId());
         }
         if (QWidget *fw = aw->focusWidget())
@@ -2933,6 +2941,7 @@ void QApplicationPrivate::closePopup(QWidget *popup)
 
 static void setAutoCapture(HWND h)
 {
+    qDebug() << __FUNCTION__ << h << QWidget::find(h);
     if (autoCaptureWnd)
         releaseAutoCapture();
     autoCaptureWnd = h;
@@ -2942,6 +2951,7 @@ static void setAutoCapture(HWND h)
 static void releaseAutoCapture()
 {
     if (autoCaptureWnd) {
+        qDebug() << __FUNCTION__ << QWidget::find(autoCaptureWnd);
         ReleaseCapture();
         autoCaptureWnd = 0;
     }
@@ -3037,6 +3047,7 @@ void qt_win_eatMouseMove()
 void QApplication::winMouseButtonUp()
 {
     qt_button_down = 0;
+    qDebug() << __FUNCTION__ << "calling releaseAutoCapture";
     releaseAutoCapture();
 }
 
@@ -3337,10 +3348,11 @@ bool QETWidget::translateMouseEvent(const MSG &msg)
             // the popup disappeared. Replay the event
             QWidget* w = QApplication::widgetAt(gpos.x, gpos.y);
             if (w && !QApplicationPrivate::isBlockedByModal(w)) {
-                Q_ASSERT(w->testAttribute(Qt::WA_WState_Created));
+                Q_ASSERT(w->testAttribute(Qt::WA_WState_Created));                
                 HWND hwndTarget = w->effectiveWinId();
-                if (QWidget::mouseGrabber() == 0)
-                    setAutoCapture(hwndTarget);
+                if (QWidget::mouseGrabber() == 0) {
+                    qDebug() << __FUNCTION__ << "Calling setAutoCapture" << w;
+                    setAutoCapture(hwndTarget);                }
                 if (!w->isActiveWindow())
                     w->activateWindow();
                 POINT widgetpt = gpos;
@@ -3364,11 +3376,15 @@ bool QETWidget::translateMouseEvent(const MSG &msg)
         if ((type == QEvent::MouseButtonPress ||
               type == QEvent::MouseButtonDblClick) && bs == button) {
             Q_ASSERT(testAttribute(Qt::WA_WState_Created));
-            if (QWidget::mouseGrabber() == 0)
+            if (QWidget::mouseGrabber() == 0) {
+                qDebug() << __FUNCTION__ << "Calling setAutoCapture" << this;
                 setAutoCapture(internalWinId());
+            }
         } else if (type == QEvent::MouseButtonRelease && bs == 0) {
-            if (QWidget::mouseGrabber() == 0)
+            if (QWidget::mouseGrabber() == 0) {
+                qDebug() << __FUNCTION__ << "calling releaseAutoCapture";
                 releaseAutoCapture();
+            }
         }
 
         const QPoint globalPos(gpos.x,gpos.y);
@@ -3705,6 +3721,7 @@ bool QETWidget::translateTabletEvent(const MSG &msg, PACKET *localPacketBuf,
             if (qt_win_ignoreNextMouseReleaseEvent) {
                 qt_win_ignoreNextMouseReleaseEvent = false;
                 if (qt_button_down && qt_button_down->internalWinId() == autoCaptureWnd) {
+                    qDebug() << __FUNCTION__ << "calling releaseAutoCapture";
                     releaseAutoCapture();
                     qt_button_down = 0;
                 }
diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp
index 5fe698e..0fd20ce 100644
--- a/src/gui/kernel/qwidget_win.cpp
+++ b/src/gui/kernel/qwidget_win.cpp
@@ -881,6 +881,7 @@ void QWidgetPrivate::grabMouseWhileInWindow()
         if (mouseGrb)
             mouseGrb->releaseMouse();
         Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
+        qDebug() << __FUNCTION__ << "SetCapture" << q;
         SetCapture(q->effectiveWinId());
         mouseGrb = q;
 #ifndef QT_NO_CURSOR
@@ -897,6 +898,7 @@ void QWidget::grabMouse()
             mouseGrb->releaseMouse();
         journalRec = SetWindowsHookEx(WH_JOURNALRECORD, (HOOKPROC)qJournalRecordProc, GetModuleHandle(0), 0);
         Q_ASSERT(testAttribute(Qt::WA_WState_Created));
+        qDebug() << __FUNCTION__ << "SetCapture" << this;
         SetCapture(effectiveWinId());
         mouseGrb = this;
 #ifndef QT_NO_CURSOR
@@ -913,6 +915,7 @@ void QWidget::grabMouse(const QCursor &cursor)
             mouseGrb->releaseMouse();
         journalRec = SetWindowsHookEx(WH_JOURNALRECORD, (HOOKPROC)qJournalRecordProc, GetModuleHandle(0), 0);
         Q_ASSERT(testAttribute(Qt::WA_WState_Created));
+        qDebug() << __FUNCTION__ << "SetCapture" << this;
         SetCapture(effectiveWinId());
         mouseGrbCur = new QCursor(cursor);
         SetCursor(mouseGrbCur->handle());
