To correctly use Qt, you need to set up a QtGui.QApplication
or QtCore.QCoreApplication
and use it's event loop to process events.
This should work:
#from utils import sigint
import functools
from PyQt4.QtCore import QTimer, QCoreApplication
app = QCoreApplication([])
def onTimer(initParams):
print initParams
print "HERE"
# your code here...
def update():
print "Upd"
myInitParams = "Init!"
timerCallback = functools.partial(onTimer, myInitParams)
myTimer = QTimer()
myTimer.timeout.connect(timerCallback)
myTimer.start(1000) #once a sec
t = QTimer()
t.start(500)
t.timeout.connect(update)
# use a timer to stop the event loop after some time
stopTimer = QTimer(timeout=app.quit, singleShot=True)
stopTimer.start(4000)
app.exec_()
Edit:
In your updated version you don't keep any reference to your timer object you create in the PlayMarkerCall
method. When myTimer
goes out of scope, it is destroyed (together with the underlying C++ Qt object), that's why your timer never fires.
And you can't pass parameters when you connect a signal to a slots, at that time you only set up the connection. Parameters can only be passed when the signal is emitted, to do that you could create a class derived from QTimer
and override it's timerEvent
method to emit a signal with arguments specified when instantiating the Timer.