Safely close database connections and delete backends
Also fix NewClosure leak caused by disconnected object signals
This commit is contained in:
@@ -223,10 +223,12 @@ Application::~Application() {
|
||||
|
||||
for (QThread *thread : threads_) {
|
||||
thread->wait();
|
||||
thread->deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Application::MoveToNewThread(QObject *object) {
|
||||
QThread *Application::MoveToNewThread(QObject *object) {
|
||||
|
||||
QThread *thread = new QThread(this);
|
||||
|
||||
@@ -234,6 +236,9 @@ void Application::MoveToNewThread(QObject *object) {
|
||||
|
||||
thread->start();
|
||||
threads_ << thread;
|
||||
|
||||
return thread;
|
||||
|
||||
}
|
||||
|
||||
void Application::MoveToThread(QObject *object, QThread *thread) {
|
||||
@@ -241,6 +246,38 @@ void Application::MoveToThread(QObject *object, QThread *thread) {
|
||||
object->moveToThread(thread);
|
||||
}
|
||||
|
||||
void Application::Exit() {
|
||||
|
||||
wait_for_exit_ << collection()
|
||||
<< playlist_backend()
|
||||
<< device_manager()
|
||||
<< internet_services();
|
||||
|
||||
connect(collection(), SIGNAL(ExitFinished()), this, SLOT(ExitReceived()));
|
||||
collection()->Exit();
|
||||
|
||||
connect(playlist_backend(), SIGNAL(ExitFinished()), this, SLOT(ExitReceived()));
|
||||
playlist_backend()->ExitAsync();
|
||||
|
||||
connect(device_manager(), SIGNAL(ExitFinished()), this, SLOT(ExitReceived()));
|
||||
device_manager()->Exit();
|
||||
|
||||
connect(internet_services(), SIGNAL(ExitFinished()), this, SLOT(ExitReceived()));
|
||||
internet_services()->Exit();
|
||||
|
||||
database()->Close();
|
||||
|
||||
}
|
||||
|
||||
void Application::ExitReceived() {
|
||||
|
||||
disconnect(sender(), 0, this, 0);
|
||||
|
||||
wait_for_exit_.removeAll(sender());
|
||||
if (wait_for_exit_.isEmpty()) emit ExitFinished();
|
||||
|
||||
}
|
||||
|
||||
void Application::AddError(const QString& message) { emit ErrorAdded(message); }
|
||||
void Application::ReloadSettings() { emit SettingsChanged(); }
|
||||
void Application::OpenSettingsDialogAtPage(SettingsDialog::Page page) { emit SettingsDialogRequested(page); }
|
||||
|
||||
Reference in New Issue
Block a user