[PyQt] problem of pyqtSignal in multi threads

Lion lionweb at qq.com
Fri May 28 02:34:43 BST 2010


version 1:
class worker(QtCore.QThread):
    trigger = QtCore.pyqtSignal(FunctionType,list,dict)


    def timer(self):
        import time
        print '1 sec'
        reactor.callLater(1,self.timer)


    def RCall(self,func,args,keys):
        print 'good'
        import time
        time.sleep(5)
        func(*args,**keys)
        
    def run(self):
        self.trigger.connect(self.RCall)
        self.MCall(mainWin.msgg)
        reactor.run(installSignalHandlers=0)


    def MCall(self, fun, *args, **keys):
        self.trigger.emit(fun,args,keys)



the version works , but what i confused is that the signal block the mainthread rather than the new thread.


version 2:


def RCall(func,args,keys):
    print 'good'
    import time
    time.sleep(5)
    func(*args,**keys)



class worker(QtCore.QThread):
    trigger = QtCore.pyqtSignal(FunctionType,list,dict)


    def timer(self):
        import time
        print '1 sec'
        reactor.callLater(1,self.timer)
        
    def run(self):
        self.trigger.connect(RCall)
        self.MCall(mainWin.msgg)
        reactor.run(installSignalHandlers=0)


    def MCall(self, fun, *args, **keys):
        self.trigger.emit(fun,args,keys)


the version DON'T WORK...  without any error, but the slot never triggered


version 3:


def RCall(func,args,keys):
    print 'good'
    import time
    time.sleep(5)
    func(*args,**keys)



class worker(QtCore.QThread):
    trigger = QtCore.pyqtSignal(FunctionType,list,dict)


    def timer(self):
        import time
        print '1 sec'
        reactor.callLater(1,self.timer)
        
    def run(self):
        self.MCall(mainWin.msgg)
        reactor.run(installSignalHandlers=0)


    def MCall(self, fun, *args, **keys):
        self.trigger.emit(fun,args,keys)




thread = worker()
thread.trigger.connect(RCall)


this version work perfectly.


now , What trouble me most is who will be the receiver of pyqtSignal exactly???
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100528/0ff73179/attachment-0001.html>


More information about the PyQt mailing list