Mike C. Mike C. - 2 months ago 17
Python Question

QTimer isn't calling myfunction as expected

In the code below the first function gets called but the second function doesn't. What am I doing wrong?

def time_cursor_plot(self):
print 'function called'
t = QtCore.QTimer()
t.setInterval(1000)
t.timeout.connect(self.start_timer)
t.start()

def start_timer(self):
print ' this one too'

Answer

the method start_timer is in the same class? otherwise remove "self".

def time_cursor_plot(self):       
    print 'function called'
    t = QtCore.QTimer()
    t.setInterval(1000)
    t.timeout.connect(start_timer)
    t.start()

def start_timer(self):
    print ' this one too'