2016-09-19 27 views
0

在下面的代碼中,第一個函數被調用,但第二個函數沒有調用。我究竟做錯了什麼?QTimer未按預期調用myfunction

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' 
+1

你讓計時器被垃圾收集。 – ekhumoro

+0

你的代碼示例沒有意義......你有沒有改變方法名稱?什麼是start_timer()方法? –

回答

1

start_timer方法是在同一個類中嗎?否則刪除「自我」。

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' 
+0

self是對類實例的引用 –