Fix Qt object lifetime handling

Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
Loren Eteval
2026-10-07 20:42:21 +08:00
parent 720f823cf6
commit 1881cb6aab
11 changed files with 551 additions and 17 deletions
+28 -2
View File
@@ -333,9 +333,15 @@ class TextEditorWindow(AppQMainWindow):
pass
if not Mixins.qObjectIsValid(self):
return True
if index == Storage.UserActivatedItemIndex():
showMBoxNewChangesNextTime(parent=self, method=showChangesMethod)
if not Mixins.qObjectIsValid(self):
return True
self.markAsSaved()
return True
@@ -346,10 +352,15 @@ class TextEditorWindow(AppQMainWindow):
None, _('Save File'), filter=_('Text files (*.json);;All files (*)')
)
if not Mixins.qObjectIsValid(self, self.jsonEditor):
return
if filename:
try:
content = self.jsonEditor.toPlainText()
with open(filename, 'w', encoding='utf-8') as file:
file.write(self.jsonEditor.toPlainText())
file.write(content)
except Exception as ex:
# Any non-exit exceptions
@@ -437,7 +448,14 @@ class TextEditorWindow(AppQMainWindow):
"""Handle button clicked."""
if button == mbox.button0:
# Save
if self.save(showChangesMethod='exec'):
saved = self.save(showChangesMethod='exec')
if not Mixins.qObjectIsValid(self, mbox):
event.ignore()
return
if saved:
mbox.close()
event.accept()
@@ -447,6 +465,11 @@ class TextEditorWindow(AppQMainWindow):
# Discard
self.markAsSaved()
if not Mixins.qObjectIsValid(self, mbox):
event.ignore()
return
mbox.close()
event.accept()
@@ -459,6 +482,9 @@ class TextEditorWindow(AppQMainWindow):
# Show the MessageBox and wait for the user to close it
mbox.exec()
if not Mixins.qObjectIsValid(self):
return
if event.isAccepted():
super().closeEvent(event)
else: