Skip to content

Commit

Permalink
Fix crash when recreating Results window/tab
Browse files Browse the repository at this point in the history
* We need to set the Details Dialog's previous instance to None when recreating a new Results window
otherwise Qt crashes since we are probably dereferencing a dangling reference.
* Also fixes Results tab not showing up when selecting it from the View menu.
  • Loading branch information
glubsy committed Aug 20, 2020
1 parent 9f223f3 commit 3382bd5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
24 changes: 17 additions & 7 deletions qt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def _setup(self):
"IgnoreListDialog",
parent=self.main_window,
model=self.model.ignore_list_dialog)
self.ignoreListDialog.accepted.connect(self.main_window.onDialogAccepted)

self.excludeListDialog = self.main_window.createPage(
"ExcludeListDialog",
Expand All @@ -97,7 +96,8 @@ def _setup(self):
else:
self.ignoreListDialog = IgnoreListDialog(
parent=parent_window, model=self.model.ignore_list_dialog)
self.excludeDialog = ExcludeListDialog(parent=parent_window)
self.excludeDialog = ExcludeListDialog(
app=self, parent=parent_window, model=self.model.exclude_list_dialog)

self.deletionOptions = DeletionOptions(
parent=parent_window,
Expand Down Expand Up @@ -231,6 +231,10 @@ def show_details(self):
def showResultsWindow(self):
if self.resultWindow is not None:
if self.use_tabs:
if self.main_window.indexOfWidget(self.resultWindow) < 0:
self.main_window.addTab(
self.resultWindow, "Results", switch=True)
return
self.main_window.showTab(self.resultWindow)
else:
self.resultWindow.show()
Expand Down Expand Up @@ -281,18 +285,25 @@ def ignoreListTriggered(self):
# we have not instantiated and populated it in their internal list yet
index = self.main_window.addTab(
self.ignoreListDialog, "Ignore List", switch=True)
# if not self.main_window.tabWidget.isTabVisible(index):
elif not self.ignoreListDialog.isVisible() and not self.main_window.isTabVisible(index):
index = self.main_window.addTab(
self.ignoreListDialog, "Ignore List", switch=True)
# self.main_window.showTab(self.ignoreListDialog)
self.main_window.setTabVisible(index, True)
self.main_window.setCurrentIndex(index)
else:
self.model.ignore_list_dialog.show()

def excludeListTriggered(self):
if self.main_window:
if self.use_tabs:
index = self.main_window.indexOfWidget(self.excludeListDialog)
if index < 0:
index = self.main_window.addTab(
self.excludeListDialog, "Exclude List", switch=True)
elif not self.excludeListDialog.isVisible() and not self.main_window.isTabVisible(index):
index = self.main_window.addTab(
self.excludeListDialog, "Exclude List", switch=True)
# self.main_window.showTab(self.excludeListDialog)
self.main_window.setTabVisible(index, True)
self.main_window.setCurrentIndex(index)
else:
Expand Down Expand Up @@ -362,15 +373,14 @@ def create_results_window(self):
# or simply delete it on close which is probably cleaner:
self.details_dialog.setAttribute(Qt.WA_DeleteOnClose)
self.details_dialog.close()
# self.details_dialog.setParent(None) # seems unnecessary
# if we don't do the following, Qt will crash when we recreate the Results dialog
self.details_dialog.setParent(None)
if self.resultWindow is not None:
self.resultWindow.close()
self.resultWindow.setParent(None)
if self.use_tabs:
self.resultWindow = self.main_window.createPage(
"ResultWindow", parent=self.main_window, app=self)
self.main_window.addTab(
self.resultWindow, "Results", switch=False)
else: # We don't use a tab widget, regular floating QMainWindow
self.resultWindow = ResultWindow(self.directories_dialog, self)
self.directories_dialog._updateActionsState()
Expand Down
9 changes: 6 additions & 3 deletions qt/tabbed_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TabWindow(QMainWindow):
def __init__(self, app, **kwargs):
super().__init__(None, **kwargs)
self.app = app
self.pages = {}
self.pages = {} # This is currently not used anywhere
self.menubar = None
self.menuList = set()
self.last_index = -1
Expand Down Expand Up @@ -142,6 +142,7 @@ def updateMenuBar(self, page_index=None):
and not page_type == "IgnoreListDialog" else False)
self.app.actionDirectoriesWindow.setEnabled(
False if page_type == "DirectoriesDialog" else True)
# FIXME add ExcludeListDialog here too

self.previous_widget_actions = active_widget.specific_actions
self.last_index = current_index
Expand All @@ -158,12 +159,14 @@ def createPage(self, cls, **kwargs):
parent = kwargs.get("parent", self)
model = kwargs.get("model")
page = IgnoreListDialog(parent, model)
page.accepted.connect(self.onDialogAccepted)
elif cls == "ExcludeListDialog":
app = kwargs.get("app", app)
parent = kwargs.get("parent", self)
model = kwargs.get("model")
page = ExcludeListDialog(app, parent, model)
self.pages[cls] = page
page.accepted.connect(self.onDialogAccepted)
self.pages[cls] = page # Not used, might remove
return page

def addTab(self, page, title, switch=False):
Expand Down Expand Up @@ -208,7 +211,7 @@ def getCount(self):

# --- Events
def appWillSavePrefs(self):
# Right now this is useless since the first spawn dialog inside the
# Right now this is useless since the first spawned dialog inside the
# QTabWidget will assign its geometry after restoring it
prefs = self.app.prefs
prefs.mainWindowIsMaximized = self.isMaximized()
Expand Down

0 comments on commit 3382bd5

Please sign in to comment.