Display Python Console Messages In Qmessagebox
I'm importing files to a MySQL DB using the LOAD DATA INFILE command. Some files may have an error which results in a console message like: mysql.connector.errors.DatabaseError:
Solution 1:
If the SQL library is using standard Python output, you could try to overwrite sys.stderr
and sys.stdout
with any object that implements a write method:
import sys
classTextBoxStderr:def__init__(self):
self.textbox = QTextEdit()
defwrite(self, errmsg):
self.textbox.append(errmsg)
box_stderr = TextBoxStderr()
sys.stderr = box_stderr
# ... Call Import Operation ...# If any error was appended to the text box, show itif box_stderr.textbox.toPlainText():
box_stderr.textbox.show()
Any text sent to stderr will be appended to a QTextEdit. Make sure you rollback the original object after the operation is complete:
sys.sterr = sys.__stderr__
Post a Comment for "Display Python Console Messages In Qmessagebox"