2017-09-30 3 views
0

all。about pyqt5 about button.clicked.connect

mk_btnをクリックしたときに空白にしたいのですが、その額はcntです。だから私はself.resultTable.setRowCount(cnt)を使用し、私はcs_btnをcliked場合は、私はget_inという名前の関数を使用したい。 get_inにはcntが必要です。 しかしself.cs_btn.clicked.connect(self.get_in(cnt))はcntを取らない。 どうすれば修正できますか?

私を助けてください。

class MyWindow(QMainWindow, form_class): 
    def __init__(self): 
     super().__init__() 
     self.setupUi(self) 

     self.kiwoom = Kiwoom() 
     self.kiwoom.commConnect() 
     self.mk_btn.clicked.connect(self.makelist) 
     self.cs_btn.clicked.connect(self.get_in(cnt)) 


    def makelist(self): 
     self.kiwoom.getConditionLoad() 
     self.kiwoom.sendCondition("0154", self.kiwoom.condition[0], 0, 1) 
     cnt = len(self.kiwoom.cl) 
     self.resultTable.setRowCount(cnt) 
     return cnt 

    def get_in(self, cnt): 
     print(cnt) 
     for i in range(cnt): 
      self.kiwoom.dynamicCall("SetInputValue(QString, QString)", "종목코드", self.kiwoom.cl[i]) 
      self.kiwoom.dynamicCall("CommRqData(QString, QString, int, QString)", "주식기본정보요청", "opt10001", 0, "0101") 
      print(self.kiwoom.name2) 
      """ 
      self.resultTable.setItem(i, 0, QTableWidgetItem(self.kiwoom.cl[i])) 
      self.resultTable.setItem(i, 1, QTableWidgetItem(self.kiwoom.name2)) 
      self.resultTable.setItem(i, 3, QTableWidgetItem(self.kiwoom.per2)) 
      self.resultTable.setItem(i, 4, QTableWidgetItem(self.kiwoom.pbr2)) 
      """ 
      time.sleep(0.5) 

答えて

1

あなたはその存在がするまで持続するので、あなたがその情報を格納するクラスのメンバを作成する必要があり、別の方法でアクセスすることができるようにしたい場合にのみ、そのコンテキスト内に存在するように可変cntはローカルですオブジェクトが解放されます。あなたの場合:

class MyWindow(QMainWindow, form_class): 
    def __init__(self): 
     super().__init__() 
     self.setupUi(self) 
     self.cnt = 0 
     self.kiwoom = Kiwoom() 
     self.kiwoom.commConnect() 
     self.mk_btn.clicked.connect(self.makelist) 
     self.cs_btn.clicked.connect(self.get_in) 


    def makelist(self): 
     self.kiwoom.getConditionLoad() 
     self.kiwoom.sendCondition("0154", self.kiwoom.condition[0], 0, 1) 
     self.cnt = len(self.kiwoom.cl) 
     self.resultTable.setRowCount(self.cnt) 

    def get_in(sel): 
     print(self.cnt) 
     for i in range(self.cnt): 
      [...]