GUI main 部分,Work2是线程类
timer 调用线程类中的一个方法
实例化线程
self.s2_thread=Worker2()
定时器绑定要做的事情以及这个事情需要多长时间触发
self.log_get=QtCore.QTimer() self.log_get.singleShot(30000,self.s2_thread.get_mem_error_logfile_content) self.log_get.singleShot(90000,self.s2_thread.get_mem_right_logfile_content)
定义触发开始的调用方法
def qtimer_get_log(self):
self.log_get.start()
将调用方法和信号绑定
QtCore.QObject.connect(self.log_get, QtCore.SIGNAL("get_log_start()"), self.qtimer_get_log)
线程Qthread部分
在线程的run中根据需要的地方发起激活定时器的信号
class Worker2(QtCore.QThread): def __init__(self, parent=None): QtCore.QThread.__init__(self, parent)
def get_mem_error_logfile_content(self):
filename=host_list[‘app75‘][‘autologfilename‘]
with open(filename,‘r‘) as f:
self.log_30_sec=f.read()
print ‘#‘*30
def get_mem_right_logfile_content(self):
filename=host_list[‘app75‘][‘autologfilename‘]
with open(filename,‘r‘) as f:
self.log_90_sec=f.read()
print ‘*‘*30 def run(self): ...... self.emit(QtCore.SIGNAL("get_log_start()")) ......
原文:http://www.cnblogs.com/leomo/p/6097085.html