From 8bf1f9203b4016362e1f9f15f1e5b8efddad1b8e Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 21 Mar 2024 14:10:36 +0200 Subject: [PATCH] plugins/screenshot: Fix a crash in ScreenShotSource2::marshal() There are behavior differences between QFutureInterface and QPromise. The QFutureWatcher::finished() signal will be emitted in both cases when the promise reports results or it is canceled. --- .../screenshot/screenshotdbusinterface2.cpp | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/plugins/screenshot/screenshotdbusinterface2.cpp b/src/plugins/screenshot/screenshotdbusinterface2.cpp index 9d8a28645e..9a677af927 100644 --- a/src/plugins/screenshot/screenshotdbusinterface2.cpp +++ b/src/plugins/screenshot/screenshotdbusinterface2.cpp @@ -151,8 +151,6 @@ class ScreenShotSource2 : public QObject public: explicit ScreenShotSource2(const QFuture &future); - bool isCancelled() const; - bool isCompleted() const; void marshal(ScreenShotSinkPipe2 *sink); virtual QVariantMap attributes() const; @@ -219,21 +217,16 @@ ScreenShotSource2::ScreenShotSource2(const QFuture &future) : m_future(future) { m_watcher = new QFutureWatcher(this); - connect(m_watcher, &QFutureWatcher::finished, this, &ScreenShotSource2::completed); - connect(m_watcher, &QFutureWatcher::canceled, this, &ScreenShotSource2::cancelled); + connect(m_watcher, &QFutureWatcher::finished, this, [this]() { + if (!m_future.isValid()) { + Q_EMIT cancelled(); + } else { + Q_EMIT completed(); + } + }); m_watcher->setFuture(m_future); } -bool ScreenShotSource2::isCancelled() const -{ - return m_future.isCanceled(); -} - -bool ScreenShotSource2::isCompleted() const -{ - return m_future.isFinished(); -} - QVariantMap ScreenShotSource2::attributes() const { return QVariantMap();