[PyQt] Segmentation fault using QThread

Flavio sixdegreesoit at yahoo.it
Sun Sep 16 11:51:47 BST 2007

Hi all,
i'm getting a segmentation fault when using a QThread to run a background 
task. here is a minimal program reproducing my problem

import sys, time
from PyQt4 import QtGui, QtCore

app = QtGui.QApplication(sys.argv)
win = QtGui.QMainWindow()
table = QtGui.QTextEdit()

def update_table(data):

class workerThread(QtCore.QThread):
    def __init__(self, r):
        self.request = r
        self.result = ''
        self.signal = QtCore.SIGNAL("thread_done(PyObject*)")
    def run(self):
        # simulate a time consuming computation
        self.result = self.request.replace('e', 'oa'); time.sleep(5)
        # result ready
        self.emit(self.signal, self.result)

thread = workerThread(u'test')
app.connect(thread, QtCore.SIGNAL("thread_done(PyObject*)"), update_table)


the programs runs just fine, but i get a segmentation fault as soon as i close 
the window (but not if i do before thread has finished).
What's strange is that everything is fine if a don't use unicode strings (i.e 
replace u'test' with just 'test' or use self.result = 
str(self.request.replace...) )

Am i doing something wrong, or is this just a bug?

python version 2.4.4
pyqt version 4.0.1
debian etch

Thanks in advance.

P.S. is it required to keep references to emit arguments in the thread class 
as i've read on this list? why? (i.e. using
self.emit(self.signal, self.result)
instead of
self.request.replace('e', 'oa'))

More information about the PyQt mailing list