From 20dc2d63fd462d26ee542beb27f57df93426e61e Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 14 Aug 2016 21:11:24 -0400 Subject: [PATCH] qt: save prefs on close more predictably Ticket #379 reports crashes on quit due to `willSavePrefs` being called when result and details dialogs are already freed. I can't reproduce the crash, but it's still a bad idea to rely on the timing of `aboutToQuit()` to launch this process. This commits uses a more predictable place to emit `willSavePrefs` and I'm pretty sure it will fix the crash at #379. --- qt/app.py | 14 +++++++------- qt/directories_dialog.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qt/app.py b/qt/app.py index aa2a382b..c452af72 100644 --- a/qt/app.py +++ b/qt/app.py @@ -7,7 +7,7 @@ import sys import os.path as op -from PyQt5.QtCore import QTimer, QObject, QCoreApplication, QUrl, pyqtSignal +from PyQt5.QtCore import QTimer, QObject, QUrl, pyqtSignal from PyQt5.QtGui import QDesktopServices from PyQt5.QtWidgets import QApplication, QFileDialog, QDialog, QMessageBox @@ -73,7 +73,6 @@ class DupeGuru(QObject): # In some circumstances, the nag is hidden by other window, which may make the user think # that the application haven't launched. QTimer.singleShot(0, self.finishedLaunching) - QCoreApplication.instance().aboutToQuit.connect(self.application_will_terminate) def _setupActions(self): # Setup actions that are common to both the directory dialog and the results window. @@ -158,6 +157,12 @@ class DupeGuru(QObject): if self.resultWindow is not None: self.resultWindow.show() + def shutdown(self): + self.willSavePrefs.emit() + self.prefs.save() + self.model.save() + QApplication.quit() + #--- Signals willSavePrefs = pyqtSignal() @@ -170,11 +175,6 @@ class DupeGuru(QObject): "you set your system locale properly." QMessageBox.warning(self.directories_dialog, "Wrong Locale", msg) - def application_will_terminate(self): - self.willSavePrefs.emit() - self.prefs.save() - self.model.save() - def clearPictureCacheTriggered(self): title = tr("Clear Picture Cache") msg = tr("Do you really want to remove all your cached picture analysis?") diff --git a/qt/directories_dialog.py b/qt/directories_dialog.py index 6a81d23a..b0e193b9 100644 --- a/qt/directories_dialog.py +++ b/qt/directories_dialog.py @@ -8,7 +8,7 @@ from PyQt5.QtCore import QRect, Qt from PyQt5.QtWidgets import ( QWidget, QFileDialog, QHeaderView, QVBoxLayout, QHBoxLayout, QTreeView, QAbstractItemView, QSpacerItem, QSizePolicy, QPushButton, QMainWindow, QMenuBar, QMenu, QLabel, - QApplication, QComboBox + QComboBox ) from PyQt5.QtGui import QPixmap, QIcon @@ -232,7 +232,7 @@ class DirectoriesDialog(QMainWindow): if not self.app.confirm(title, msg): event.ignore() if event.isAccepted(): - QApplication.quit() + self.app.shutdown() #--- Events def addFolderTriggered(self):