Subclassing and Signal connect on a same widget crashes PySide application on exit.

In pyside, I wanted to do something like these,
class MyTextLine(QLineEdit):
    def focusInEvent(self, e):
        #do something
        QLineEdit.focusInEvent(self, e)
....

widget = MyTextLine(QLineEdit)
widget.editingFinished.connect(some_callback)

However, this app tends to crash on exit. Core dump saids it is something about destructor of a signal manager.

Details are rather vague, but I managed to avoid crash deleting signal-connect.

class MyTextLine(QLineEdit):
    def focusInEvent(self, e):
        #do something
        QLineEdit.focusInEvent(self, e)
    def setCallback(self, cb):
        self.cb = cb
    def focusOutEvent(self, e):
        if hasattr(self, 'cb'): self.cb()
....
widget = MyTextLine(QLineEdit)
widget.setCallback(some_callback)

If anyone knows why this happens, please teach me! One more thing, if you use QTreeWidget having widgets on it, it seems better to do clear() it before closing your application.

Update 2015/01/25: It seems like widget.setParent(None) to suspicious widget on exit also works.

Comments

Popular posts from this blog

Calling OpenCV functions via Cython from Python 3.X.

Showing CPU/Memory usage on tmux status bar(tmuxのステータスバーにCPUとMemoryの使用状況を表示する)