PyQT5 emit 和 connect的用法详解
作者:JameScottX 时间:2022-02-08 15:15:11
对于PyQT4, PyQT5在一些使用上有着比较明显的变化有很大的变化,让人惊讶是在emit和connect上的一些变化比较有意思,相信也是QT为了更好的和Python相结合做的改进。
先上一张图:
出现 AttributeError: 'TCPWindow' object has no attribute 'connect' 这个问题说明了PyQT5不在支持PyQT4的链接信号槽方式!
对于emit使用如下:
class Server(QTcpServer):
updateServer= pyqtSignal(list)
self.emit(SIGNAL("updateServer(QString,int)"),msg,length)
上面这个需要改成
self.updateServer(str,int).emit(msg,length)
注意PyQt4还是有QString这个东西的,PyQt5我找了半天都没有了,可以直接用 str 来替代,对于QString::number 都是直接可以使用 str() 来取代,可以说很方便,更加适应Python的风格。
对于connect使用如下(以pushButton为例):
self.connect(self.pb_build_tcp,SIGNAL("released()"),self.CreateServer)
改成:
self.pb_build_tcp.released.connect(self.CreateServer)
来源:https://blog.csdn.net/qq_37389133/article/details/80707304
标签:PyQT5,emit,connect
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaScript实现全选取消效果
2023-08-27 16:26:42
![](https://img.aspxhome.com/file/2023/7/56157_0s.png)
python文件操作相关知识点总结整理
2023-05-09 02:17:42
SQLSERVER 本地查询更新操作远程数据库的代码
2023-07-23 21:58:55
如何将Python列表转换为字符串
2023-11-02 12:54:27
Google的产品设计指导思想
2008-03-23 14:15:00
![](https://img.aspxhome.com/file/UploadPic/20083/23/2008323141844207s.jpg)
pycharm使用正则表达式批量添加print括号完美从python2迁移到python3
2021-11-06 15:30:35
![](https://img.aspxhome.com/file/2023/9/68999_0s.jpg)
网页设计标准尺寸
2008-06-15 15:21:00
在ASP.NET 2.0中操作数据之三十:格式化DataList和Repeater的数据
2023-07-22 20:15:21
![](https://img.aspxhome.com/file/2023/9/76339_0s.png)
sql server 获取系统时间的方法
2023-07-17 07:05:36
Rel与CSS的联合使用
2010-02-20 13:03:00
![](https://img.aspxhome.com/file/UploadPic/20102/20/e1-23s.png)
Python人脸检测实战之疲劳检测
2021-02-23 16:31:37
![](https://img.aspxhome.com/file/2023/6/76716_0s.jpg)
asp.net生成Excel并导出下载五种实现方法
2023-07-06 11:01:16
![](https://img.aspxhome.com/file/2023/9/77189_0s.jpg)
基于Python编写一个自动关机程序
2023-07-30 08:19:20
![](https://img.aspxhome.com/file/2023/2/59822_0s.png)
10个提高网站可用性的实用技巧[译]
2009-06-12 12:37:00
![](https://img.aspxhome.com/file/UploadPic/20096/12/e110ff69d4158da954232063c6e0f6d7-48s.jpeg)
Python实现的远程登录windows系统功能示例
2022-10-09 21:26:15
php实现mysql事务处理的方法
2023-11-10 10:42:39
教你使用一行Python代码玩遍童年的小游戏
2021-05-15 10:14:00
![](https://img.aspxhome.com/file/2023/4/76104_0s.jpg)
JScript下Array对象的性能问题
2009-02-15 12:28:00
JavaScript加密解密终级指南
2008-01-03 12:25:00
![](https://img.aspxhome.com/file/UploadPic/up/2008010314121540.gif)
Python获取时间范围内日期列表和周列表的函数
2023-03-25 15:16:39
![](https://img.aspxhome.com/file/2023/8/75928_0s.png)