Merge pull request #6527 from jbroadus/wait-for-query-thread
Prevent deletion of LibraryModel object while async query is running.
This commit is contained in:
commit
fd64a5a807
|
@ -88,6 +88,7 @@ LibraryModel::LibraryModel(LibraryBackend* backend, Application* app,
|
||||||
playlists_dir_icon_(IconLoader::Load("folder-sound", IconLoader::Base)),
|
playlists_dir_icon_(IconLoader::Load("folder-sound", IconLoader::Base)),
|
||||||
playlist_icon_(IconLoader::Load("x-clementine-albums", IconLoader::Base)),
|
playlist_icon_(IconLoader::Load("x-clementine-albums", IconLoader::Base)),
|
||||||
icon_cache_(new QNetworkDiskCache(this)),
|
icon_cache_(new QNetworkDiskCache(this)),
|
||||||
|
thread_pool_(this),
|
||||||
init_task_id_(-1),
|
init_task_id_(-1),
|
||||||
use_pretty_covers_(false),
|
use_pretty_covers_(false),
|
||||||
show_dividers_(true) {
|
show_dividers_(true) {
|
||||||
|
@ -129,7 +130,10 @@ LibraryModel::LibraryModel(LibraryBackend* backend, Application* app,
|
||||||
backend_->UpdateTotalSongCountAsync();
|
backend_->UpdateTotalSongCountAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryModel::~LibraryModel() { delete root_; }
|
LibraryModel::~LibraryModel() {
|
||||||
|
thread_pool_.waitForDone();
|
||||||
|
delete root_;
|
||||||
|
}
|
||||||
|
|
||||||
void LibraryModel::set_pretty_covers(bool use_pretty_covers) {
|
void LibraryModel::set_pretty_covers(bool use_pretty_covers) {
|
||||||
if (use_pretty_covers != use_pretty_covers_) {
|
if (use_pretty_covers != use_pretty_covers_) {
|
||||||
|
@ -769,7 +773,7 @@ void LibraryModel::LazyPopulate(LibraryItem* parent, bool signal) {
|
||||||
|
|
||||||
void LibraryModel::ResetAsync() {
|
void LibraryModel::ResetAsync() {
|
||||||
QFuture<LibraryModel::QueryResult> future =
|
QFuture<LibraryModel::QueryResult> future =
|
||||||
QtConcurrent::run(this, &LibraryModel::RunQuery, root_);
|
QtConcurrent::run(&thread_pool_, this, &LibraryModel::RunQuery, root_);
|
||||||
NewClosure(future, this,
|
NewClosure(future, this,
|
||||||
SLOT(ResetAsyncQueryFinished(QFuture<LibraryModel::QueryResult>)),
|
SLOT(ResetAsyncQueryFinished(QFuture<LibraryModel::QueryResult>)),
|
||||||
future);
|
future);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QNetworkDiskCache>
|
#include <QNetworkDiskCache>
|
||||||
|
#include <QThreadPool>
|
||||||
|
|
||||||
#include "libraryitem.h"
|
#include "libraryitem.h"
|
||||||
#include "libraryquery.h"
|
#include "libraryquery.h"
|
||||||
|
@ -292,6 +293,8 @@ signals:
|
||||||
|
|
||||||
QNetworkDiskCache* icon_cache_;
|
QNetworkDiskCache* icon_cache_;
|
||||||
|
|
||||||
|
QThreadPool thread_pool_;
|
||||||
|
|
||||||
int init_task_id_;
|
int init_task_id_;
|
||||||
|
|
||||||
bool use_pretty_covers_;
|
bool use_pretty_covers_;
|
||||||
|
|
Loading…
Reference in New Issue