title: Connecting QPushButon to a method in another class in PyQt
body: <p>I am trying to connect a <code>QPushButton</code> created in class <code>A</code> with a method created in class <code>B</code> . This is my code:</p>
  
  <pre><code>class A(QMainWindow):
    def __init__(self):
      super(QMainWindow, self).__init__()
      #A lot of stuff in here
  
    def Button(self):
      self.btn = QPushButton()
      self.connect(self.btn, SIGNAL("clicked()"), B().method_1)
  
  
  class B(QMainWindow):
    def __init__(self):
      QMainWindow.__init__(self)
      #Another stuff in here too
  
    def method_1(self):
      pass
  </code></pre>
  
  <p>But, it is not working. I read this post:</p>
  
  <p><a href="https://stackoverflow.com/questions/34806921/send-and-receive-signals-from-another-class-pyqt">Send and receive signals from another class pyqt</a></p>
  
  <p>and it says that I can do it creating a <code>pyqtSignal</code>. Is there another way to do this? I mean, to connect the <code>QPushButton</code> from class <code>a</code> with <code>method_1</code> in class <code>B</code>. Hope you can help me.</p>
  
  <h2>------ EDIT ------</h2>
  
  <p>I had to make some modifications to my code and I delete the <code>button</code> method, and I put it in a <code>toolbar</code>. So now I have this: </p>
  
  <pre><code>class A(QMainWindow):
    def __init__(self):
      super(QMainWindow, self).__init__()
      #A lot of stuff in here
  
      self.toolbar = QToolBar(self)
      self.btn = QPushButton()
      self.toolbar.addWidget(self.btn)
      self.connect(self.btn, SIGNAL("clicked()"), B().method_1)
  
  class B(QMainWindow):
    def __init__(self):
      QMainWindow.__init__(self)
      #Another stuff in here too
  
    def method_1(self):
      pass
  </code></pre>
  
  <p>Hope you can help me.</p>