Skip to content

Commit

Permalink
qt: save prefs on close more predictably
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Virgil Dupras committed Aug 15, 2016
1 parent 28d2aa8 commit 20dc2d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions qt/app.py
Expand Up @@ -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

Expand Down Expand Up @@ -73,7 +73,6 @@ def _setup(self):
# 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.
Expand Down Expand Up @@ -158,6 +157,12 @@ def showResultsWindow(self):
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()

Expand All @@ -170,11 +175,6 @@ def finishedLaunching(self):
"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?")
Expand Down
4 changes: 2 additions & 2 deletions qt/directories_dialog.py
Expand Up @@ -8,7 +8,7 @@
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

Expand Down Expand Up @@ -232,7 +232,7 @@ def closeEvent(self, event):
if not self.app.confirm(title, msg):
event.ignore()
if event.isAccepted():
QApplication.quit()
self.app.shutdown()

#--- Events
def addFolderTriggered(self):
Expand Down

0 comments on commit 20dc2d6

Please sign in to comment.