Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PySide中的强制QTimer()超时_Python_Pyqt_Pyside - Fatal编程技术网

Python PySide中的强制QTimer()超时

Python PySide中的强制QTimer()超时,python,pyqt,pyside,Python,Pyqt,Pyside,我有一个pySide应用程序,它使用QTimer每分钟刷新一次状态。在某些情况下,我需要强制立即更新,然后重新启动计时器 self.timer = QTimer() self.timer.timeout.connect(self._update_status) self.timer.start(60 * 1000) 有没有办法强制计时器过期并发出超时信号?最干净的解决方案似乎就是这样: self.timer.start() # restart the timer

我有一个pySide应用程序,它使用QTimer每分钟刷新一次状态。在某些情况下,我需要强制立即更新,然后重新启动计时器

self.timer = QTimer()
self.timer.timeout.connect(self._update_status)
self.timer.start(60 * 1000)

有没有办法强制计时器过期并发出超时信号?

最干净的解决方案似乎就是这样:

        self.timer.start() # restart the timer
        self.timer.timeout.emit() # force an immediate update
也可以通过调用
setInterval(1)
强制立即更新,但这样做的缺点是,您需要在连接到信号的插槽中再次重置计时器间隔:

        self.timer.setInterval(1) # force an immediate update

    def _update_status(self):
        ...
        if self.timer.interval() == 1:
            self.timer.setInterval(60 * 1000) # reset the interval

(请注意,如果使用的间隔为零,Qt将只在事件队列被清除后发出超时信号。因此,严格来说,
setInterval(0)
不一定会强制立即更新)。

您第一次建议使用timeout.emit()效果很好,而且很简单。tnx。