title: Different ways to connect Signal to Slot
body: <p>The code below creates a <code>QLineEdit</code> and a <code>QPushButton</code>. Pushing the button updates lineedit with a current time. This functionality is achieved by connecting button's 'clicked' signal to lineedit's <code>update</code> method using <code>button.clicked.connect(line.update)</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/pMp4f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pMp4f.png" alt="enter image description here"></a></p>
  
  <pre><code>import datetime
  from PyQt4 import QtCore, QtGui
  app = QtGui.QApplication([])
  
  class LineEdit(QtGui.QLineEdit):
      def __init__(self, parent=None):
          super(LineEdit, self).__init__(parent=parent)
  
      def update(self, some=None):
          self.setText(str(datetime.datetime.now()))
  
  line = LineEdit()
  line.show()
  
  class PushButton(QtGui.QPushButton):
      def __init__(self, parent=None):
          super(PushButton, self).__init__(parent=parent)
  
  button = PushButton()
  button.show()
  
  button.clicked.connect(line.update)
  
  app.exec_()
  </code></pre>
  
  <p>Instead of using <code>button.clicked.connect(line.update)</code> we could use:</p>
  
  <p><code>QtCore.QObject.connect(button, QtCore.SIGNAL('clicked()'), line.update)</code></p>
  
  <p>or</p>
  
  <p><code>QtCore.QObject.connect(button, QtCore.SIGNAL('clicked()'), line, QtCore.SLOT("update()"))</code></p>
  
  <p>Alternatively we could declare the button's <code>customSignal</code> and connect it to the function we need:</p>
  
  <pre><code>import datetime
  from PyQt4 import QtCore, QtGui
  app = QtGui.QApplication([])
  
  
  class LineEdit(QtGui.QLineEdit):
      def __init__(self, parent=None):
          super(LineEdit, self).__init__(parent=parent)
  
      @QtCore.pyqtSlot()
      def update(self, some=None):
          self.setText(str(datetime.datetime.now()))
  
  line = LineEdit()
  line.show()
  
  
  class PushButton(QtGui.QPushButton):
      customSignal = QtCore.pyqtSignal()
      def __init__(self, parent=None):
          super(PushButton, self).__init__(parent=parent)
  
      def mousePressEvent(self, event):
          super(PushButton, self).mousePressEvent(event)
          self.customSignal.emit()
          event.ignore()
  
  
  button = PushButton()
  button.show()
  
  button.customSignal.connect(line.update)
  
  app.exec_()
  </code></pre>
  
  <p>Again, instead of using:</p>
  
  <p><code>button.customSignal.connect(line.update)</code></p>
  
  <p>we could use:</p>
  
  <p><code>QtCore.QObject.connect(button, QtCore.SIGNAL('customSignal()'), line, QtCore.SLOT("update()"))</code></p>
  
  <p>Question: Are there any drawbacks of using one approach over another?</p>