Skip to content

Commit 565b8e3

Browse files
committed
Fix incorrect calls to QMessageBox.critical
As noted in issue #14, QMessageBox is called incorrectly, resulting in an exception. This change addresses the issue.
1 parent 14392c0 commit 565b8e3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Chapter04/text_editor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ def openFile(self):
269269
with open(filename, 'r') as fh:
270270
self.textedit.setText(fh.read())
271271
except Exception as e:
272-
qtw.QMessageBox.critical(f"Could not load file: {e}")
272+
# Errata: Book contains the following line:
273+
#qtw.QMessageBox.critical(f"Could not load file: {e}")
274+
# It should read like this:
275+
qtw.QMessageBox.critical(self, f"Could not load file: {e}")
273276

274277
def saveFile(self):
275278
filename, _ = qtw.QFileDialog.getSaveFileName(
@@ -283,7 +286,10 @@ def saveFile(self):
283286
with open(filename, 'w') as fh:
284287
fh.write(self.textedit.toPlainText())
285288
except Exception as e:
286-
qtw.QMessageBox.critical(f"Could not save file: {e}")
289+
# Errata: Book contains this line:
290+
#qtw.QMessageBox.critical(f"Could not save file: {e}")
291+
# It should read like this:
292+
qtw.QMessageBox.critical(self, f"Could not load file: {e}")
287293

288294
def set_font(self):
289295
current = self.textedit.currentFont()

0 commit comments

Comments
 (0)