2011/7/19 Jeremy Sanders <[email protected]>:
> Is there an easy way to signal a result from a QRunnable? I've worked
> around this problem by replacing the code with a worker thread and a
> semaphore.
It works for me with a separate QObject-derived class, which properly
declares the signal using the new-style signal-slot API. See the
attached source code.
Hope, this helps
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class WorkerObject(QObject):
testsignal = pyqtSignal(int, int, int)
class Runnable(QRunnable):
def __init__(self):
QRunnable.__init__(self)
self.obj = WorkerObject()
def run(self):
self.obj.testsignal.emit(1, 2, 3)
class Win(QPushButton):
def __init__(self):
QPushButton.__init__(self, "Push me")
self.tp = QThreadPool()
self.clicked.connect(self.slotClicked)
def slotClicked(self):
runnable = Runnable()
runnable.obj.testsignal.connect(self.slotTestSignal)
self.tp.start(runnable)
def slotTestSignal(self, a, b, c):
print "Returning from runnable", a, b, c
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Win()
w.show()
app.exec_()
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt