python: Process finished with exit code 1 when using PyCharm and PyQt5

后端 未结 3 2037
不思量自难忘°
不思量自难忘° 2020-12-10 14:50

I have three Python(3.4.3) scripts. One of them is for controlling the .ui file generated by PyQt5. When I run the GUI program it accepts all the data and everything and whe

相关标签:
3条回答
  • 2020-12-10 15:17

    I had the same problem in pycharm, python 3.8, qt5. The stacktrace was never shown for qt errors inside pycharm; running the file from cmd the error was shown correctly instead.

    I solved by doing the following: open Edit Configurations of the file you want to run, scroll down and check the box Emulate terminal in output console.

    0 讨论(0)
  • 2020-12-10 15:28

    You have used self.sender.setText(email)

    This is probably causing the problem in my opinion because, "sender" is the name in QObject's function and it does not have any setText attribute, so there may be the problem.

    You have to specifically call the widget and setText to it. For this, you can use instances of the py file of the layout creator.

    I had the same issue when I was trying to use this self.ui.lineEdit().text() Here, the problem was -> I was calling the lineEdit function, whereas I had to use it's one attribute.

    0 讨论(0)
  • 2020-12-10 15:32

    I have dealt with the same problem, and the answer is twofold:

    1. The reason it's crashing could be any number of things. It's probably a programming bug, calling a function that doesn't exist, passing a widget instead of a layout, etc. But since you're not getting useful output you don't know where to look for the culprit. This is caused by:
    2. PyQT raises and catches exceptions, but doesn't pass them along. Instead it just exits with a status of 1 to show an exception was caught.

    To catch the exceptions, you need to overwrite the sys exception handler:

    # Back up the reference to the exceptionhook
    sys._excepthook = sys.excepthook
    
    def my_exception_hook(exctype, value, traceback):
        # Print the error and traceback
        print(exctype, value, traceback)
        # Call the normal Exception hook after
        sys._excepthook(exctype, value, traceback)
        sys.exit(1)
    
    # Set the exception hook to our wrapping function
    sys.excepthook = my_exception_hook
    

    Then in your execution code, wrap it in a try/catch.

    try:
        sys.exit(app.exec_())
    except:
        print("Exiting")
    
    0 讨论(0)
提交回复
热议问题