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:
parent
489cd31ee9
commit
8bf1f9203b
1 changed files with 7 additions and 14 deletions
|
@ -151,8 +151,6 @@ class ScreenShotSource2 : public QObject
|
||||||
public:
|
public:
|
||||||
explicit ScreenShotSource2(const QFuture<QImage> &future);
|
explicit ScreenShotSource2(const QFuture<QImage> &future);
|
||||||
|
|
||||||
bool isCancelled() const;
|
|
||||||
bool isCompleted() const;
|
|
||||||
void marshal(ScreenShotSinkPipe2 *sink);
|
void marshal(ScreenShotSinkPipe2 *sink);
|
||||||
|
|
||||||
virtual QVariantMap attributes() const;
|
virtual QVariantMap attributes() const;
|
||||||
|
@ -219,21 +217,16 @@ ScreenShotSource2::ScreenShotSource2(const QFuture<QImage> &future)
|
||||||
: m_future(future)
|
: m_future(future)
|
||||||
{
|
{
|
||||||
m_watcher = new QFutureWatcher<QImage>(this);
|
m_watcher = new QFutureWatcher<QImage>(this);
|
||||||
connect(m_watcher, &QFutureWatcher<QImage>::finished, this, &ScreenShotSource2::completed);
|
connect(m_watcher, &QFutureWatcher<QImage>::finished, this, [this]() {
|
||||||
connect(m_watcher, &QFutureWatcher<QImage>::canceled, this, &ScreenShotSource2::cancelled);
|
if (!m_future.isValid()) {
|
||||||
|
Q_EMIT cancelled();
|
||||||
|
} else {
|
||||||
|
Q_EMIT completed();
|
||||||
|
}
|
||||||
|
});
|
||||||
m_watcher->setFuture(m_future);
|
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
|
QVariantMap ScreenShotSource2::attributes() const
|
||||||
{
|
{
|
||||||
return QVariantMap();
|
return QVariantMap();
|
||||||
|
|
Loading…
Reference in a new issue