From 0c9e2eae483dc777b9f53819d23805abc80e51d8 Mon Sep 17 00:00:00 2001
From: Alexandru Croitor <alexandru.croitor@qt.io>
Date: Thu, 20 Apr 2017 16:51:31 +0200
Subject: [PATCH] Fix crash on macOS when closing last tab of a window

Because of weird interaction between deleteLater(),
Qt::WA_DeleteOnClose, and QQuickRenderControlPrivate::windowDestroyed()
which executes all the deferred deletions at a bad time, there were
some use-after-free crashes.

The workaround is not to close the window when the last tab is closed,
but rather create a new tab, like the behavior was on non-macOS
platforms.

Task-number: QTBUG-58982
Change-Id: I00295838c298af382cac78bb22c47d6de60e7755
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
---
 examples/webenginewidgets/demobrowser/browsermainwindow.cpp | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
index 926c4a5d7..327d7a9d3 100644
--- a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
+++ b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
@@ -167,13 +167,9 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags)
             m_navigationBar, SLOT(setVisible(bool)));
     connect(m_tabWidget, SIGNAL(toolBarVisibilityChangeRequested(bool)),
             m_bookmarksToolbar, SLOT(setVisible(bool)));
-#if defined(Q_OS_OSX)
-    connect(m_tabWidget, SIGNAL(lastTabClosed()),
-            this, SLOT(close()));
-#else
+
     connect(m_tabWidget, SIGNAL(lastTabClosed()),
             m_tabWidget, SLOT(newTab()));
-#endif
 
     slotUpdateWindowTitle();
     loadDefaultState();
-- 
GitLab