Segfault after signal emit
-
I am trying to switch from pyqt4 to pyside and having trouble when emitting a signal from a worker thread.
the result is a segmentation fault. The same thing works for pyt4.
the gui consists of one button which starts the worker thread and should emit a signal when done.
the worker_thread is started after clicking the button, but the segfault appears when emitting the signal.
(this is meant to be a generic example, not (yet) a useful application...)Thanks for the help!
@
import sysfrom PySide import QtCore as QTC
from PySide import QtGui as QTG
import ui_signalTest_pyside as myUi'''
from PyQt4 import QtCore as QTC
from PyQt4 import QtGui as QTG
import ui_signalTest_pyqt as myUi
'''class Window(QTG.QWidget,myUi.Ui_Form):
def init(self, parent = None):
super(Window, self).init(parent)
self.setupUi(self)self.worker_thread = Worker() self.connect(self.worker_thread,QTC.SIGNAL("doSomething"),\ self.myFunc) self.connect(self.pushButton, QTC.SIGNAL("clicked()"),\ self.startThread) def startThread(self): self.worker_thread.start() def myFunc(self,msg): print 'signal recieved:', msg
class Worker(QTC.QThread):
def __init__(self, parent = None): QTC.QThread.__init__(self,parent) def run(self): N = 10000 for i in range(N): for j in range(N): i+j msg = 'loop finished' self.emit(QTC.SIGNAL("doSomething"),msg)
app = QTG.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())@
-
yes i did find a solution:
@
import sysfrom PySide import QtCore as QTC
from PySide import QtGui as QTG
import ui_signalTest_pyside as myUi'''
from PyQt4 import QtCore as QTC
from PyQt4 import QtGui as QTG
import ui_signalTest_pyqt as myUi
'''class Window(QTG.QWidget,myUi.Ui_Form):
def init(self, parent = None):
super(Window, self).init(parent)
self.setupUi(self)self.worker_thread = Worker() self.connect(self.pushButton,QTC.SIGNAL("clicked()"), self.startThread) self.worker_thread.mySignal.connect(self.myFunc, QTC.Qt.QueuedConnection) def startThread(self): self.worker_thread.start() def myFunc(self,msg): print 'signal recieved:', msg
class Worker(QTC.QThread):
mySignal = QTC.Signal(str) def __init__(self, parent = None): QTC.QThread.__init__(self,parent) def run(self): N = 10000 for i in range(N): for j in range(N): i+j msg = 'loop finished' self.mySignal.emit(msg)
app = QTG.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
@