From decd0a1dc617f0f561636b281f3f369468e21b5b Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 14 Jan 2025 06:35:51 +0100 Subject: [PATCH] TagReaderClient: Connect TagReaderReplyPtr Makes sure TagReaderReplyPtr is not deleted too early. Partial fix for #1633 --- src/tagreader/tagreaderclient.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/tagreader/tagreaderclient.cpp b/src/tagreader/tagreaderclient.cpp index 45a25a6151..04799da9c6 100644 --- a/src/tagreader/tagreaderclient.cpp +++ b/src/tagreader/tagreaderclient.cpp @@ -384,7 +384,11 @@ void TagReaderClient::SaveSongsPlaycountAsync(const SongList &songs) { Q_ASSERT(QThread::currentThread() != thread()); for (const Song &song : songs) { - SaveSongPlaycountAsync(song.url().toLocalFile(), song.playcount()); + SharedPtr connection = make_shared(); + TagReaderReplyPtr reply = SaveSongPlaycountAsync(song.url().toLocalFile(), song.playcount()); + *connection = QObject::connect(&*reply, &TagReaderReply::Finished, this, [reply, connection]() { + QObject::disconnect(*connection); + }, Qt::QueuedConnection); } } @@ -417,7 +421,11 @@ void TagReaderClient::SaveSongsRatingAsync(const SongList &songs) { Q_ASSERT(QThread::currentThread() != thread()); for (const Song &song : songs) { - SaveSongRatingAsync(song.url().toLocalFile(), song.rating()); + SharedPtr connection = make_shared(); + TagReaderReplyPtr reply = SaveSongRatingAsync(song.url().toLocalFile(), song.rating()); + *connection = QObject::connect(&*reply, &TagReaderReply::Finished, this, [reply, connection]() { + QObject::disconnect(*connection); + }, Qt::QueuedConnection); } }