Always call QFutureWatcher::setFuture after connects

This commit is contained in:
Jonas Kvinge 2021-06-16 00:30:21 +02:00
parent d2d3f58a14
commit 8699790e78
15 changed files with 27 additions and 27 deletions

View File

@ -930,8 +930,8 @@ void CollectionModel::ResetAsync() {
QFuture<CollectionModel::QueryResult> future = QtConcurrent::run(this, &CollectionModel::RunQuery, root_);
#endif
QFutureWatcher<CollectionModel::QueryResult> *watcher = new QFutureWatcher<CollectionModel::QueryResult>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<CollectionModel::QueryResult>::finished, this, &CollectionModel::ResetAsyncQueryFinished);
watcher->setFuture(future);
}

View File

@ -617,7 +617,6 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, co
QFuture<SongList> future = QtConcurrent::run(app_->collection_backend(), &CollectionBackend::GetAlbumSongs, song.effective_albumartist(), song.effective_album(), QueryOptions());
#endif
QFutureWatcher<SongList> *watcher = new QFutureWatcher<SongList>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<SongList>::finished, this, [=]() {
SongList songs = watcher->result();
watcher->deleteLater();
@ -634,6 +633,7 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, co
cover_save_tasks_.insert(id, song);
}
});
watcher->setFuture(future);
}
else {
if (result.is_jpeg()) {
@ -661,7 +661,6 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, co
QFuture<SongList> future = QtConcurrent::run(app_->collection_backend(), &CollectionBackend::GetAlbumSongs, song.effective_albumartist(), song.effective_album(), QueryOptions());
#endif
QFutureWatcher<SongList> *watcher = new QFutureWatcher<SongList>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<SongList>::finished, this, [=]() {
SongList songs = watcher->result();
watcher->deleteLater();
@ -671,6 +670,7 @@ void AlbumCoverChoiceController::SaveCoverEmbeddedAutomatic(const Song &song, co
QMutexLocker l(&mutex_cover_save_tasks_);
cover_save_tasks_.insert(id, song);
});
watcher->setFuture(future);
}
else {
app_->album_cover_loader()->SaveEmbeddedCoverAsync(song.url().toLocalFile(), cover_filename);

View File

@ -249,8 +249,8 @@ void DeviceProperties::UpdateFormats() {
QFuture<bool> future = QtConcurrent::run(std::bind(&ConnectedDevice::GetSupportedFiletypes, device, &supported_formats_));
#endif
QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<bool>::finished, this, &DeviceProperties::UpdateFormatsFinished);
watcher->setFuture(future);
ui_->formats_stack->setCurrentWidget(ui_->formats_page_loading);
updating_formats_ = true;

View File

@ -415,8 +415,8 @@ void EditTagDialog::SetSongs(const SongList &s, const PlaylistItemList &items) {
QFuture<QList<Data>> future = QtConcurrent::run(this, &EditTagDialog::LoadData, s);
#endif
QFutureWatcher<QList<Data>> *watcher = new QFutureWatcher<QList<Data>>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<QList<Data>>::finished, this, &EditTagDialog::SetSongsFinished);
watcher->setFuture(future);
}
@ -1178,7 +1178,6 @@ void EditTagDialog::SaveData() {
++save_art_pending_;
QFuture<QByteArray> future = QtConcurrent::run(&ImageUtils::SaveImageToJpegData, ref.cover_result_.image);
QFutureWatcher<QByteArray> *watcher = new QFutureWatcher<QByteArray>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<QByteArray>::finished, this, [=]() {
TagReaderReply *reply = TagReaderClient::Instance()->SaveEmbeddedArt(ref.current_.url().toLocalFile(), watcher->result());
QObject::connect(reply, &TagReaderReply::Finished, this, [this, reply, ref]() {
@ -1186,12 +1185,12 @@ void EditTagDialog::SaveData() {
}, Qt::QueuedConnection);
watcher->deleteLater();
});
watcher->setFuture(future);
}
else if (!embedded_cover_from_file.isEmpty()) { // Save existing file on disk as embedded cover.
++save_art_pending_;
QFuture<QByteArray> future = QtConcurrent::run(&ImageUtils::FileToJpegData, embedded_cover_from_file);
QFutureWatcher<QByteArray> *watcher = new QFutureWatcher<QByteArray>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<QByteArray>::finished, this, [=]() {
TagReaderReply *reply = TagReaderClient::Instance()->SaveEmbeddedArt(ref.current_.url().toLocalFile(), watcher->result());
QObject::connect(reply, &TagReaderReply::Finished, this, [this, reply, ref]() {
@ -1199,6 +1198,7 @@ void EditTagDialog::SaveData() {
}, Qt::QueuedConnection);
watcher->deleteLater();
});
watcher->setFuture(future);
}
}
else if (ref.cover_action_ == UpdateCoverAction_Delete) {

View File

@ -293,8 +293,8 @@ void TrackSelectionDialog::accept() {
// Save tags in the background
QFuture<void> future = QtConcurrent::run(&TrackSelectionDialog::SaveData, data_);
QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this);
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<void>::finished, this, &TrackSelectionDialog::AcceptFinished);
watcher->setFuture(future);
return;
}

View File

@ -237,12 +237,12 @@ bool GstEngine::Play(const quint64 offset_nanosec) {
QFuture<GstStateChangeReturn> future = current_pipeline_->SetState(GST_STATE_PLAYING);
QFutureWatcher<GstStateChangeReturn> *watcher = new QFutureWatcher<GstStateChangeReturn>();
watcher->setFuture(future);
int pipeline_id = current_pipeline_->id();
QObject::connect(watcher, &QFutureWatcher<GstStateChangeReturn>::finished, this, [this, watcher, offset_nanosec, pipeline_id]() {
PlayDone(watcher->result(), offset_nanosec, pipeline_id);
watcher->deleteLater();
});
watcher->setFuture(future);
if (is_fading_out_to_pause_) {
current_pipeline_->SetState(GST_STATE_PAUSED);

View File

@ -216,11 +216,11 @@ void MoodbarItemDelegate::StartLoadingColors(const QUrl &url, const QByteArray &
QFuture<ColorVector> future = QtConcurrent::run(MoodbarRenderer::Colors, bytes, style_, qApp->palette());
QFutureWatcher<ColorVector> *watcher = new QFutureWatcher<ColorVector>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<ColorVector>::finished, this, [this, watcher, url]() {
ColorsLoaded(url, watcher->result());
watcher->deleteLater();
});
watcher->setFuture(future);
}
@ -247,11 +247,11 @@ void MoodbarItemDelegate::StartLoadingImage(const QUrl &url, Data *data) {
QFuture<QImage> future = QtConcurrent::run(MoodbarRenderer::RenderToImage, data->colors_, data->desired_size_);
QFutureWatcher<QImage> *watcher = new QFutureWatcher<QImage>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<QImage>::finished, this, [this, watcher, url]() {
ImageLoaded(url, watcher->result());
watcher->deleteLater();
});
watcher->setFuture(future);
}

View File

@ -74,8 +74,8 @@ void TagFetcher::StartFetch(const SongList &songs) {
else {
QFuture<QString> future = QtConcurrent::mapped(songs_, GetFingerprint);
fingerprint_watcher_ = new QFutureWatcher<QString>(this);
fingerprint_watcher_->setFuture(future);
QObject::connect(fingerprint_watcher_, &QFutureWatcher<QString>::resultReadyAt, this, &TagFetcher::FingerprintFound);
fingerprint_watcher_->setFuture(future);
for (const Song &song : songs_) {
emit Progress(song, tr("Fingerprinting song"));
}

View File

@ -396,11 +396,11 @@ bool OrganizeDialog::SetFilenames(const QStringList &filenames) {
songs_future_ = QtConcurrent::run(this, &OrganizeDialog::LoadSongsBlocking, filenames);
#endif
QFutureWatcher<SongList> *watcher = new QFutureWatcher<SongList>();
watcher->setFuture(songs_future_);
QObject::connect(watcher, &QFutureWatcher<SongList>::finished, this, [this, watcher]() {
SetSongs(watcher->result());
watcher->deleteLater();
});
watcher->setFuture(songs_future_);
SetLoadingSongs(true);
return true;

View File

@ -431,11 +431,11 @@ void Playlist::ItemReload(const QPersistentModelIndex &idx, const Song &old_meta
if (item) {
QFuture<void> future = item->BackgroundReload();
QFutureWatcher<void> *watcher = new QFutureWatcher<void>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<void>::finished, this, [this, watcher, idx, old_metadata, metadata_edit]() {
ItemReloadComplete(idx, old_metadata, metadata_edit);
watcher->deleteLater();
});
watcher->setFuture(future);
}
}
@ -1471,8 +1471,8 @@ void Playlist::Restore() {
QFuture<PlaylistItemList> future = QtConcurrent::run(backend_, &PlaylistBackend::GetPlaylistItems, id_);
#endif
QFutureWatcher<PlaylistItemList> *watcher = new QFutureWatcher<PlaylistItemList>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<PlaylistItemList>::finished, this, &Playlist::ItemsLoaded);
watcher->setFuture(future);
}

View File

@ -404,8 +404,8 @@ TagCompleter::TagCompleter(CollectionBackend *backend, Playlist::Column column,
QFuture<TagCompletionModel*> future = QtConcurrent::run(&InitCompletionModel, backend, column);
QFutureWatcher<TagCompletionModel*> *watcher = new QFutureWatcher<TagCompletionModel*>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<TagCompletionModel*>::finished, this, &TagCompleter::ModelReady);
watcher->setFuture(future);
}

View File

@ -226,11 +226,11 @@ void PlaylistManager::Save(const int id, const QString &filename, const Playlist
QFuture<SongList> future = QtConcurrent::run(playlist_backend_, &PlaylistBackend::GetPlaylistSongs, id);
#endif
QFutureWatcher<SongList> *watcher = new QFutureWatcher<SongList>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<SongList>::finished, this, [this, watcher, filename, path_type]() {
ItemsLoadedForSavePlaylist(watcher->result(), filename, path_type);
watcher->deleteLater();
});
watcher->setFuture(future);
}
}

View File

@ -69,8 +69,8 @@ void PlaylistGeneratorInserter::Load(Playlist *destination, const int row, const
QFuture<PlaylistItemList> future = QtConcurrent::run(PlaylistGeneratorInserter::Generate, generator, dynamic_count);
QFutureWatcher<PlaylistItemList> *watcher = new QFutureWatcher<PlaylistItemList>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<PlaylistItemList>::finished, this, &PlaylistGeneratorInserter::Finished);
watcher->setFuture(future);
}

View File

@ -117,8 +117,8 @@ void SmartPlaylistSearchPreview::RunSearch(const SmartPlaylistSearch &search) {
ui_->count_label->hide();
QFuture<PlaylistItemList> future = QtConcurrent::run(DoRunSearch, generator_);
QFutureWatcher<PlaylistItemList> *watcher = new QFutureWatcher<PlaylistItemList>();
watcher->setFuture(future);
QObject::connect(watcher, &QFutureWatcher<PlaylistItemList>::finished, this, &SmartPlaylistSearchPreview::SearchFinished);
watcher->setFuture(future);
}

View File

@ -19,9 +19,9 @@ TEST(ConcurrentRunTest, ConcurrentRun0StartAndWait) {
QThreadPool threadpool;
QFuture<int> future = QtConcurrent::run(&threadpool, &f);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, watcher.result());
@ -38,9 +38,9 @@ TEST(ConcurrentRunTest, ConcurrentRun1StartAndWait) {
int i = 1336;
QFuture<int> future = QtConcurrent::run(&threadpool, &g, i);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, watcher.result());
@ -58,9 +58,9 @@ TEST(ConcurrentRunTest, ConcurrentRun2StartAndWait) {
QThreadPool threadpool;
QFuture<int> future = QtConcurrent::run(&threadpool, &max, i, j);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(42, watcher.result());
@ -79,9 +79,9 @@ TEST(ConcurrentRunTest, ConcurrentRun3StartAndWait) {
QThreadPool threadpool;
QFuture<int> future = QtConcurrent::run(&threadpool, &sum, i, j, k);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(102, watcher.result());
@ -111,9 +111,9 @@ TEST(ConcurrentRunTest, ConcurrentRunVoidFunction1Start) {
int n = 10;
QFuture<void> future = QtConcurrent::run(&threadpool, &aFunction, &n);
QFutureWatcher<void> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, n);
@ -126,9 +126,9 @@ TEST(ConcurrentRunTest, ConcurrentRunVoidFunction2Start) {
int n = 10, m = 11;
QFuture<void> future = QtConcurrent::run(&threadpool, &bFunction, &n, &m);
QFutureWatcher<void> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, n);
EXPECT_EQ(1338, m);
@ -142,9 +142,9 @@ TEST(ConcurrentRunTest, ConcurrentRunVoidFunction3Start) {
int n = 10, m = 11, o = 12;
QFuture<void> future = QtConcurrent::run(&threadpool, &cFunction, &n, &m, &o);
QFutureWatcher<void> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, n);
EXPECT_EQ(1338, m);
@ -167,9 +167,9 @@ TEST(ConcurrentRunTest, ConcurrentRunVoidBindFunctionStart) {
int nb = 10;
QFuture<void> future = QtConcurrent::run(&threadpool, std::bind(&A::f, &a, &nb));
QFutureWatcher<void> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(11, nb);