我正在开发一个 pyqt-gui,它应该有可能在每个选定的时间(例如每 2 分钟)刷新一次数据加载。在这个循环中,gui 应该能够响应事件等。
代码如下所示:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.uic import *
class TeleModul (QMainWindow):
def __init__(self, *args):
QWidget.__init__(self, *args)
loadUi ("telemodul.ui",self)
.....
def on_ButtonSuchen_clicked (self):
QTimer.singleShot(60000, self.RefreshData())
def RefreshData(self):
...do something ...
点击 ButtonSuchen 引发错误:
TypeError: arguments did not match any overloaded call:
QTimer.singleShot(int, QObject, SLOT()): argument 2 has unexpected type 'NoneType' QTimer.singleShot(int, callable): argument 2 has unexpected type 'NoneType'
问题出在哪里或者整合这个循环的最佳方式是什么?
最佳答案
传递可调用对象,而不是调用它的结果:
QTimer.singleShot(60000, self.RefreshData)
关于python - 我如何在pyqt中集成一个定时循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14120889/