From bad151445176edc55fb37fbae56b3c8a1ab1feb5 Mon Sep 17 00:00:00 2001
From: Michal Klocek <michal.klocek@qt.io>
Date: Wed, 2 Aug 2017 15:51:41 +0200
Subject: [PATCH] Fix simplebrowser crash on exit while downloading

On webengine profile destruction all download
items in progress are canceled. This triggered
stateChanged of QWebEngineDownloadItem which
called lambda function on already deleted object.

Do not use lambda functions in this case.

Change-Id: Ia1d359fe47204baa51f1380d1c3547c28550bc28
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Viktor Engelmann <viktor.engelmann@qt.io>
---
 .../webenginewidgets/simplebrowser/downloadwidget.cpp     | 8 ++------
 examples/webenginewidgets/simplebrowser/downloadwidget.h  | 4 +++-
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/examples/webenginewidgets/simplebrowser/downloadwidget.cpp b/examples/webenginewidgets/simplebrowser/downloadwidget.cpp
index a80366f77..cc16d245b 100644
--- a/examples/webenginewidgets/simplebrowser/downloadwidget.cpp
+++ b/examples/webenginewidgets/simplebrowser/downloadwidget.cpp
@@ -62,14 +62,10 @@ DownloadWidget::DownloadWidget(QWebEngineDownloadItem *download, QWidget *parent
     });
 
     connect(m_download, &QWebEngineDownloadItem::downloadProgress,
-            [this](qint64, qint64) {
-        updateWidget();
-    });
+            this, &DownloadWidget::updateWidget);
 
     connect(m_download, &QWebEngineDownloadItem::stateChanged,
-            [this](QWebEngineDownloadItem::DownloadState) {
-        updateWidget();
-    });
+            this, &DownloadWidget::updateWidget);
 
     updateWidget();
 }
diff --git a/examples/webenginewidgets/simplebrowser/downloadwidget.h b/examples/webenginewidgets/simplebrowser/downloadwidget.h
index e8cf42825..02c42fb44 100644
--- a/examples/webenginewidgets/simplebrowser/downloadwidget.h
+++ b/examples/webenginewidgets/simplebrowser/downloadwidget.h
@@ -63,8 +63,10 @@ signals:
     // this download from the downloads list.
     void removeClicked(DownloadWidget *self);
 
-private:
+private slots:
     void updateWidget();
+
+private:
     QString withUnit(qreal bytes);
 
     QWebEngineDownloadItem *m_download;
-- 
GitLab