diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 216537e..268cf33 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -693,6 +693,7 @@ void QGuiApplicationPrivate::updateBlockedStatus(QWindow *window)
 
 void QGuiApplicationPrivate::showModalWindow(QWindow *modal)
 {
+    qDebug() << __FUNCTION__ << modal;
     self->modalWindowList.prepend(modal);
 
     // Send leave for currently entered window if it should be blocked
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index e262f3f..aadb2aa 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -472,6 +472,7 @@ QWindow::SurfaceType QWindow::surfaceType() const
 */
 void QWindow::setVisible(bool visible)
 {
+    qDebug() << __FUNCTION__ << this << visible;
     Q_D(QWindow);
 
     if (d->visible == visible)
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index 5124960..8754ec0 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -514,6 +514,7 @@ void QDialog::open()
 
 int QDialog::exec()
 {
+    qDebug() << Q_FUNC_INFO << '>';
     Q_D(QDialog);
 
     if (d->eventLoop) {
@@ -530,7 +531,9 @@ int QDialog::exec()
     setAttribute(Qt::WA_ShowModal, true);
     setResult(0);
 
+    qDebug() << Q_FUNC_INFO << " calling show()>";
     show();
+    qDebug() << Q_FUNC_INFO << " called show()<";
 
     QPointer<QDialog> guard = this;
     if (d->nativeDialogInUse) {
@@ -551,6 +554,7 @@ int QDialog::exec()
         d->helperDone(static_cast<QDialog::DialogCode>(res), d->platformHelper());
     if (deleteOnClose)
         delete this;
+    qDebug() << Q_FUNC_INFO << '<' << res;
     return res;
 }
 
@@ -705,14 +709,25 @@ void QDialog::closeEvent(QCloseEvent *e)
 void QDialog::setVisible(bool visible)
 {
     Q_D(QDialog);
-    if (!testAttribute(Qt::WA_DontShowOnScreen) && d->canBeNativeDialog() && d->setNativeDialogVisible(visible))
+    qDebug() << "QDialog::setVisible" << this << visible
+             << "WA_DontShowOnScreen=" << testAttribute(Qt::WA_DontShowOnScreen)
+             << "WA_WState_ExplicitShowHide=" << testAttribute(Qt::WA_WState_ExplicitShowHide)
+             << "WA_WState_Hidden=" << testAttribute(Qt::WA_WState_Hidden);
+
+    if (!testAttribute(Qt::WA_DontShowOnScreen) && d->canBeNativeDialog() && d->setNativeDialogVisible(visible)) {
+        qDebug("R1");
         return;
+    }
 
     if (visible) {
-        if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
+        if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) {
+            qDebug("R2");
             return;
+        }
 
+        qDebug() << "QDialog::setVisible: Calling QWidget::setVisible>";
         QWidget::setVisible(visible);
+        qDebug() << "QDialog::setVisible: Calling QWidget::setVisible<";
         showExtension(d->doShowExtension);
         QWidget *fw = window()->focusWidget();
         if (!fw)
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 7734715..254b12e 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -2886,6 +2886,7 @@ void QWidget::setWindowModality(Qt::WindowModality windowModality)
 void QWidgetPrivate::setModal_sys()
 {
     Q_Q(QWidget);
+    qDebug() << Q_FUNC_INFO << this << q->windowModality();
     if (q->windowHandle())
         q->windowHandle()->setModality(q->windowModality());
 }
@@ -7681,6 +7682,7 @@ void QWidget::setUpdatesEnabled(bool enable)
 */
 void QWidget::show()
 {
+    qDebug() << ">QWidget::show()" << this;
     Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(data->window_flags);
     if (defaultState == Qt::WindowFullScreen)
         showFullScreen();
@@ -7688,6 +7690,7 @@ void QWidget::show()
         showMaximized();
     else
         setVisible(true); // FIXME: Why not showNormal(), like QWindow::show()?
+    qDebug() << "<QWidget::show()";
 }
 
 /*! \internal
@@ -7873,11 +7876,17 @@ void QWidgetPrivate::show_sys()
 
     QWindow *window = q->windowHandle();
 
+    qDebug() << Q_FUNC_INFO << q << window << "WA_DontShowOnScreen=" <<
+                q->testAttribute(Qt::WA_DontShowOnScreen)
+             << "isWindow=" << q->isWindow()
+             << "modality" << q->windowModality();
+
     if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
         invalidateBuffer(q->rect());
         q->setAttribute(Qt::WA_Mapped);
         if (q->isWindow() && q->windowModality() != Qt::NonModal && window) {
             // add our window to the modal window list
+            qDebug() << Q_FUNC_INFO << q << "Calling QGuiApplicationPrivate::showModalWindow";
             QGuiApplicationPrivate::showModalWindow(window);
         }
         return;
@@ -8088,6 +8097,7 @@ void QWidget::setVisible(bool visible)
         // whether we need to inform the parent widget immediately
         bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden);
         // we are no longer hidden
+        qDebug() << Q_FUNC_INFO << this << "clearing WA_WState_Hidden1";
         setAttribute(Qt::WA_WState_Hidden, false);
 
         if (needUpdateGeometry)
@@ -8157,6 +8167,7 @@ void QWidget::setVisible(bool visible)
         if (!isWindow() && parentWidget()) // && !d->getOpaqueRegion().isEmpty())
             parentWidget()->d_func()->setDirtyOpaqueRegion();
 
+        qDebug() << Q_FUNC_INFO << this << "setting WA_WState_Hidden";
         setAttribute(Qt::WA_WState_Hidden);
         setAttribute(Qt::WA_WState_ExplicitShowHide);
         if (testAttribute(Qt::WA_WState_Created))
@@ -10506,10 +10517,14 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
 #endif
 
     if (!wasCreated) {
-        if (isWindow() || parentWidget()->isVisible())
+        if (isWindow() || parentWidget()->isVisible()) {
+            qDebug() << Q_FUNC_INFO << this << "setting WA_WState_Hidden";
             setAttribute(Qt::WA_WState_Hidden, true);
-        else if (!testAttribute(Qt::WA_WState_ExplicitShowHide))
+        } else if (!testAttribute(Qt::WA_WState_ExplicitShowHide)) {
+            qDebug() << Q_FUNC_INFO << this << "clearing WA_WState_Hidden";
             setAttribute(Qt::WA_WState_Hidden, false);
+        }
+
     }
 
     d->updateIsOpaque();
@@ -10609,6 +10624,7 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
     data.window_flags = f;
     q->setAttribute(Qt::WA_WState_Created, false);
     q->setAttribute(Qt::WA_WState_Visible, false);
+    qDebug() << Q_FUNC_INFO << "clearing WA_WState_Hidden";
     q->setAttribute(Qt::WA_WState_Hidden, false);
 
     if (newparent && wasCreated && (q->testAttribute(Qt::WA_NativeWindow) || (f & Qt::Window)))
