SoFunction
Updated on 2024-11-15

PyQT5 emit and connect usage in detail

For PyQT4, PyQT5 in some of the use of more obvious changes in the use of big changes, people are surprised at the emit and connect some of the changes are more interesting, I believe it is also QT in order to better combine with Python to do the improvement.

First a picture:

AttributeError: 'TCPWindow' object has no attribute 'connect' This problem indicates that PyQT5 is not supporting the PyQT4 link signaling slot method!

For emit use the following:

class Server(QTcpServer):
  updateServer= pyqtSignal(list)
(SIGNAL("updateServer(QString,int)"),msg,length)

The above needs to be changed to

(str,int).emit(msg,length)

Note that PyQt4 still have QString this thing, PyQt5 I looked for half a day are no longer, you can directly use str to replace, for QString::number are directly can be used str() to replace, can be said to be very convenient, more adapted to the style of Python.

For connect use the following (using pushButton as an example):

(self.pb_build_tcp,SIGNAL("released()"),)

Change to:

self.pb_build_tcp.()

Above this PyQT5 emit and connect usage details is all that I have shared with you, I hope to give you a reference, and I hope you support me more.