PyQt: no msg (traceback) error on exit

My PyQt application no longer prints an error (stderr?) On the console.

I use QtDesigner and import the user interface as follows:

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5.uic import loadUiType
Ui_MainWindow, QMainWindow = loadUiType("test.ui")

class Main(QMainWindow, Ui_MainWindow):
    """Main window"""
    def __init__(self,parent=None):
        super(Main, self).__init__(parent)
        self.setupUi(self)
        self.pushButton.clicked.connect(self.testfunc)

   def testfunc(self):
        print(9/0)

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    main = Main()
    main.show()
    sys.exit(app.exec_())

test.ui contains a QPushButton and a label. When I call testfunc (which explicitly gives an error) in an application other than Qt, I get an error message, traceback, etc. When I execute this code, it just exits.

I wrote a PyQt application without QtDesigner before, and it printed errors on the console as expected. What is the difference with QtDesigner and inheritance?

+8
source share
1 answer

, , PyQt-5.5. . Python PyQt5.

, , :

$ python test.py
Traceback (most recent call last):
  File "test.py", line 213, in testfunc
    print(9/0)
ZeroDivisionError: division by zero
Aborted (core dumped)

, , , (.. python script). , , try/except , sys.excepthook.

, IDE Python, .

+8

Source: https://habr.com/ru/post/1675737/


All Articles