Hi,<br><br>I have some problems with the signal and slots mechanism in threaded applications. The problem appears when the QObject.connect() call have to be made in another thread then the receiving slot. One example is if I have a worker thread that dynamically creates other worker threads. When I make the connect() call in the worker thread and connect to a slot that for example adds items to a QWidgetList I get the following error:
<br><br>QObject::connect: Cannot queue arguments of type 'QModelIndex'<br>
(Make sure 'QModelIndex' is registed using qRegisterMetaType().)<br><br><br>I found a way to handle the problem, but It is a rather ugly hack. I was therefore wondering if there was a better way?<br><br>An example of how I deal with the problem now:
<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 newString(self,item):<br> self.list.addItem(str(item))<br> <br> <br>class MyWorkerThread(QThread):<br> def __init__(self,parrent):<br> QThread.__init__(self)
<br> self.p=parrent<br> <br> def run(self):<br> list =[] <br> for i in range (1,10):<br> s=MySubWorkerThread(i)<br> QObject.connect(s,SIGNAL("newString(PyQt_PyObject)"),
self.newString)<br> s.start()<br> list.append(s)<br> self.exec_() <br> <br> def newString(self,host):<br> self.emit(SIGNAL("newString(PyQt_PyObject)"),host)<br><br>
<br>class MySubWorkerThread(QThread):<br> def __init__(self,i):<br> QThread.__init__(self)<br> self.i=i<br> <br> def run(self):<br> self.emit(SIGNAL("newString(PyQt_PyObject)"),str(
self.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>
QObject.connect(worker,SIGNAL("newString(PyQt_PyObject)"),window.newString)<br> app.exec_()<br> <br><br><br>Regards,<br>Ole<br>