我试图在每5秒内动态更改图像,第一次正确显示,之后没有显示任何内容,这是我的代码,
def imageSelect(self):
name = self.selectImageFromDb()#Fetch image name from database one by one
self.pic.clear()
myPixmap = QtGui.QPixmap(_fromUtf8(path + "images/" + name))
self.pic.setPixmap(myPixmap)
self.pic.show()
threading.Timer(3, self.imageSelect).start()`
答案 0 :(得分:0)
如果我走线
threading.Timer(3, self.imageSelect).start()
超出函数imageSelect()
我可以重现这种行为。我收到错误消息:
QObject::startTimer: Timers can only be used with threads started with QThread
所以我用QTimer
代替(成功):
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.imageSelect)
self.timer.start(1000) # interval in milliseconds