= Sending Python values with signals and slots = On the `#pyqt` channel on Freenode, `Khertan` asked about sending Python values via Qt's signals and slots mechanism. The following example uses the `PyQt_PyObject` value declaration with an old-style signal-slot connection, and again when the signal is emitted, to communicate a Python dictionary. '''Note:''' The comments about new style connections in the code are incorrect. {{{ #!python import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Window(QWidget): def __init__(self, parent = None): QWidget.__init__(self, parent) button = QPushButton(self.tr("Click me")) self.resultLabel = QLabel(self.tr("...")) # New style: uses the connect method of a pyqtSignal object. self.connect(button, SIGNAL("clicked()"), self.handleClick) # Old style: uses the SIGNAL function to describe the signal. self.connect(self, SIGNAL("sendValue(PyQt_PyObject)"), self.handleValue) layout = QVBoxLayout(self) layout.addWidget(button) layout.addWidget(self.resultLabel) def handleClick(self): # Old style: emits the signal using the SIGNAL function. self.emit(SIGNAL("sendValue(PyQt_PyObject)"), {"abc": 123}) def handleValue(self, value): self.resultLabel.setText(repr(value)) if __name__ == "__main__": app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_()) }}}