2013-04-10 37 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!"