Signal In Pyside Not Emitted When Called By A Timer
I need to emit a signal periodically. A timer executes certain function, which emits the signal that I want. For some reason this function is not being emitted. I was able to repro
Solution 1:
As @ekhumoro said in the comments, QTimer helped a lot. I needed an event-loop. I'm posting the code to make the answer valid. I rewrote it using QTimer, which made everything simpler really. Note that I need to call QCoreApplication to run the threads. Again, this is just the minimal code to reproduce what I needed to do.
import time
from PySide import QtCore
from probeConnection import ProbeConnection
classtestSignals(QtCore.QObject):
def__init__(self):
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.tick)
self.start()
deftick(self):
print("tick")
defgetData(self):
return time.strftime('%H:%M:%S')
defstart(self):
self.timer.start(1000)
defstop(self):
self.timer.stop()
classtestConnection():
defreceiveMe(self):
print('time: ' + self.test.getData())
def__init__(self):
self.test = testSignals()
self.test.timer.timeout.connect(self.receiveMe)
app = QtCore.QCoreApplication([])
test = testConnection()
timer = QtCore.QTimer()
timer.singleShot(4000,app.exit)
app.exec_()
it produces:
ticktime: 13:23:37ticktime: 13:23:38ticktime: 13:23:39ticktime: 13:23:40
Post a Comment for "Signal In Pyside Not Emitted When Called By A Timer"