Hi,<br><br>I have a problem with passing signals a cross threads. <br>I was under the impression that when using Qt.QueuedConnection the slot would always be executed in the thread that the receiver object lived. But when I created this test application I does not seem to be doing that. Any suggestions on what the error might be?
<br><br>Btw, I'm working on a tutorial on using signal and slots with python over at <a href="http://developernew.kde.org/Development/Tutorials/101_Python_introduction_to_signal_and_slots">http://developernew.kde.org/Development/Tutorials/101_Python_introduction_to_signal_and_slots
</a> <br>Feel free to improve it. Feedback and suggestions are also most welcome. English is not my native language so I guess there are plenty of mistakes :/<br><br>from PyQt4.QtGui import *<br>from PyQt4.QtCore import *
<br>import sys<br><br>class MyUI(QMainWindow):<br> def __init__(self):<br> QMainWindow.__init__(self)<br> self.list=QListWidget()<br> self.setCentralWidget(self.list)<br> <br> def newItem(self,item):
<br> self.list.addItem(item)<br> <br> <br>class MyWorkerThread(QThread):<br> def __init__(self,ui):<br> QThread.__init__(self)<br> self.ui=ui<br> <br> def run(self):<br>
self.connect(self,SIGNAL("createdItem"),self.ui.newItem,Qt.QueuedConnection) <br> for i in range (1,10):<br> #creating items<br> self.emit(SIGNAL("createdItem"),i)<br>
self.exec_()<br><br>if __name__=="__main__":<br> app=QApplication(sys.argv)<br> window=MyUI()<br> window.show()<br> worker=MyWorkerThread(window)<br> worker.start() <br> app.exec_()<br><br><br>
This code outputs:<br>QObject: Cannot create children for a parent that is in a different thread.<br>