Skip to content

Commit

Permalink
TagReaderClient: Connect TagReaderReplyPtr
Browse files Browse the repository at this point in the history
Makes sure TagReaderReplyPtr is not deleted too early.

Partial fix for #1633
  • Loading branch information
jonaski committed Jan 14, 2025
1 parent 3e0a9fa commit decd0a1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/tagreader/tagreaderclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QMetaObject::Connection> connection = make_shared<QMetaObject::Connection>();
TagReaderReplyPtr reply = SaveSongPlaycountAsync(song.url().toLocalFile(), song.playcount());
*connection = QObject::connect(&*reply, &TagReaderReply::Finished, this, [reply, connection]() {
QObject::disconnect(*connection);
}, Qt::QueuedConnection);
}

}
Expand Down Expand Up @@ -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<QMetaObject::Connection> connection = make_shared<QMetaObject::Connection>();
TagReaderReplyPtr reply = SaveSongRatingAsync(song.url().toLocalFile(), song.rating());
*connection = QObject::connect(&*reply, &TagReaderReply::Finished, this, [reply, connection]() {
QObject::disconnect(*connection);
}, Qt::QueuedConnection);
}

}

0 comments on commit decd0a1

Please sign in to comment.