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.
This commit is contained in:
Vlad Zahorodnii 2024-03-21 14:10:36 +02:00
parent 489cd31ee9
commit 8bf1f9203b

View file

@ -151,8 +151,6 @@ class ScreenShotSource2 : public QObject
public:
explicit ScreenShotSource2(const QFuture<QImage> &future);
bool isCancelled() const;
bool isCompleted() const;
void marshal(ScreenShotSinkPipe2 *sink);
virtual QVariantMap attributes() const;
@ -219,21 +217,16 @@ ScreenShotSource2::ScreenShotSource2(const QFuture<QImage> &future)
: m_future(future)
{
m_watcher = new QFutureWatcher<QImage>(this);
connect(m_watcher, &QFutureWatcher<QImage>::finished, this, &ScreenShotSource2::completed);
connect(m_watcher, &QFutureWatcher<QImage>::canceled, this, &ScreenShotSource2::cancelled);
connect(m_watcher, &QFutureWatcher<QImage>::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();