2013-04-10 36 views
0

我試圖開始分離QProcess,並完成其中的一些事情。例如膩子隧道。我有課,以保持信息關於這兩個過程:來自獨立QProcess的Singnals

class TunnelInfo(object): 
    def __init__(self,tunnelprocess,mainprocess): 
     self.tp=tunnelprocess 
     self.mp=mainprocess 
     print "init" 
     self.mp.finished.connect(self.killTunnel) 
    def killTunnel(self,a,b): 
     print "killing tunnel" 
     print self.tp 
     self.tp.kill() 

然後我試圖執行膩子:

prcs=QtCore.QProcess(self.parent) 
prcs.startDetached(self.conf.putty_path, ['-pw',d.password,'-l',d.login,d.ip]) 
ti=self.TunnelInfo(tp,prcs) 

膩子開始確定,但信號沒有被接收......我究竟做錯了什麼?

回答

0

我發現某處startDetached很火併且忘記了。我用QThread解決了它:

class ConnectionThread(QtCore.QThread): 
    def __init__(self,parent,command,commandargs,tunnelthread=None): 
     super(ConnectionThread,self).__init__(parent.parent) 
     self.command=command 
     self.commandargs=commandargs 
     self.tunnelthread=tunnelthread 
     self.parent=parent 
     print command,commandargs 
     self.finished.connect(self.killtunnel) 
    def run(self): 
     self.process=QtCore.QProcess() 
     self.process.start(self.command,self.commandargs) 
     self.process.waitForFinished(msecs=3000000) 
    def killtunnel(self): 
     if self.tunnelthread is not None: 
      self.tunnelthread.process.kill() 
      self.tunnelthread.exit(0) 
      print "killed!"