如果时间到了,是否只能启动一次Qtimer
self.timer = QtCore.QTimer()
self.timer.setInterval(10000)
self.timer.start(800) # start only once, not every 800 milliseconds
self.timer.timeout.connect(self.function)
答案 0 :(得分:1)
为此,您必须启用singleShot
属性:
self.timer = QtCore.QTimer()
self.timer.setSingleShot(True)
self.timer.setInterval(800)
self.timer.timeout.connect(self.function)
self.timer.start()
或
QTimer.singleShot(800, self.function)
答案 1 :(得分:0)
除了eyllanesc提到的signleShot方法外, 您可以通过self.function停止计时器。
def function(self):
self.timer.stop()