3 from __future__ import with_statement
4 from __future__ import division
8 import PyQt4.QtCore as QtCore
11 class QThread44(QtCore.QThread):
13 This is to imitate QThread in Qt 4.4+ for when running on older version
14 See http://labs.trolltech.com/blogs/2010/06/17/youre-doing-it-wrong
15 (On Lucid I have Qt 4.7 and this is still an issue)
18 def __init__(self, parent = None):
19 QtCore.QThread.__init__(self, parent)
25 class Producer(QtCore.QObject):
27 data = QtCore.pyqtSignal(int)
28 done = QtCore.pyqtSignal()
31 QtCore.QObject.__init__(self)
35 print "Starting producer"
42 class Consumer(QtCore.QObject):
45 QtCore.QObject.__init__(self)
49 print "Starting consumer"
56 def print_data(self, i):
60 if __name__ == "__main__":
61 app = QtCore.QCoreApplication([])
63 producerThread = QThread44()
65 producer.moveToThread(producerThread)
66 producerThread.started.connect(producer.process)
68 consumerThread = QThread44()
70 consumer.moveToThread(consumerThread)
71 consumerThread.started.connect(consumer.process)
73 producer.data.connect(consumer.print_data)
74 producer.done.connect(consumer.print_done)
82 producer.done.connect(producer_done)
94 producerThread.finished.connect(thread_done)
95 consumerThread.finished.connect(thread_done)
97 producerThread.start()
98 consumerThread.start()
99 print "Status", app.exec_()