0

I routinely use PyDev in Eclipse for Python development. However, I'm trying PyQt for the first time in the same environment. It works well, with one exception. If the program errors out anywhere within the Qt main event loop, including within my own code, no error information is output to the PyDev console.

To demonstrate this I created the following simple PyQt app:

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication

# test.ui contains a single Push Button named pushButton
base, form = uic.loadUiType("../ui/test.ui") 

class MainWindow(base, form):
    def __init__(self, parent=None):
        super(base, self).__init__(parent)
        self.setupUi(self)
        self.pushButton.clicked.connect(self.button_pressed)

    def button_pressed(self):
        print('button pressed')
        print(invalid_variable) # intentional error
        pass

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setStyle("fusion")
    main_window = MainWindow()
    main_window.show()
    sys.exit(app.exec_())

If I place an intentional error such as print(invalid_variable) anywhere after if __name__ == '__main__': and before the app.exec_() command, the program properly terminates with a traceback and the expected NameError: name 'invalid_variable' is not defined. However, if I press the button in my dialog using the above code, button pressed appears on the console but then the application terminates silently and with no error information in the console. Other debugging operations, such as breakpoints and expressions, work fine.

Is this expected behavior? If so, what do you recommend for facilitating debugging of PyQt apps in this environment. If not, I'd appreciate insight into what I need to do to rectify the problem.

  • Python version: python-3.4.3.amd64
  • PyDev version: PyDev for Eclipse 4.3.0.201508182223
  • PyQt version: PyQt5-5.5-gpl-Py3.4-Qt5.5.0-x64

Update 2015-09-30:

When I run the test app directly with python.exe, it outputs the error correctly to stderr in both error scenarios. So this issue does seem specific to the PyDev environment. I additionally created an entirely fresh Eclipse workspace with only the Python interpreter configured and ran my test again on a freshly created PyDev project using the same source code. The results were the same.

2 Answers 2

2

This is a very old Question, but i thought I'd provide the answer since it shows up on google searches for this problem.

The issue is changes to pyqt5.5+ handling of errors, including the following code will reenable stacktrace on crashes.

It took Alot of random browsing on the internet, but eventually found the code needed to work around the problem, posted here for reference for anyone else who has the same issue. Was obvious when I finally found it. ;)

from PyQt5 import QtCore
import traceback, sys


if QtCore.QT_VERSION >= 0x50501:
    def excepthook(type_, value, traceback_):
        traceback.print_exception(type_, value, traceback_)
        QtCore.qFatal('')
sys.excepthook = excepthook

Hope this helps others.

Sign up to request clarification or add additional context in comments.

Comments

0

I had the same problem. And i added just one line:

import ipdb

So all my QT applications are showing me errors. ipdb - this is module for debugging your script, but without any setting (import only) it's works as you need

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.