2016-05-25 7 views
0

私はQTimerを使用してメソッドを開始し、タイマーを開始します。 QPushButton私はこのタイマーを停止し、別のことをする必要があります。私はボタンを押すときに、私はこのエラーを取得:QTimerでTry/exceptを使用する

TypeError: 'instancemethod' object is not connected

は、どのように私はこのエラーを回避するためにtry-exceptメソッドを使用することができます。これは私がやったことです:

def delete(self): 
    try: 
     self.tmr.timeout.disconnect(self.run_save_clock) 
     self.tmr.timeout.disconnect(self.append_Data) 
     self.data = [] 
     self.time_label_2.setText("00:00:00") 
     self.data_label.setText("000000") 

    except "TypeError: 'instancemethod' object is not connected": #HERE IS WHERE I HAVE THE PROBLEM 
     self.tmr.timeout.disconnect(self.append_Data) 
     self.data = [] 
     self.time_label_2.setText("00:00:00") 
     self.data_label.setText("000000") 

しかし、それは動作しません。 self.dataは、タイマーがアクティブな間にデータを保存する変数です。私が最初にこのメソッドに接続されている別のQPushButtonを押すと

エラーが表示されます:私はtry/except方法と間違っ

def stop(self): 
    self.saveBtn.setEnabled(True) 
    self.stopBtn.setEnabled(False) 
    self.tmr.timeout.disconnect(self.run_save_clock) 
    self.tmr.timeout.disconnect(self.append_Data) 

何をしているのですか?次のようにあなたが提起するエラーメッセージを追加するには、右「除く」の後ではなく、むしろERRORTYPEと

答えて

1

https://docs.python.org/2/tutorial/errors.htmlごとに、あなたは、エラーメッセージ文字列を含めるべきではありません。

try: 
    #something 

except TypeError: 
    #Do something here 
    print " 'instancemethod' object is not connected" 
    #Or do something here 
関連する問題