Qt::ConnectionType 解析
来源:互联网 发布:人工智能如何实现 编辑:程序博客网 时间:2024/06/04 18:18
http://blog.csdn.net/s04023083/article/details/4746544
signal/slot在底层会使用三种方式传递消息。参见QObject::connect()方法:
bool QObject::connect ( const QObject * sender, const char * signal, const QObject * receiver, const char * method, Qt::ConnectionType type = Qt::AutoCompatConnection )
最后一个参数是就是传递消息的方式了,有四个取值:
Qt::DirectConnection
When emitted, the signal is immediately delivered to the slot.
假设当前有4个slot连接到QPushButton::clicked(bool),当按钮被按下时,QT就把这4个slot按连接的时间顺序调用一遍。显然这种方式不能跨线程(传递消息)。
Qt::QueuedConnection
When emitted, the signal is queued until the event loop is able to deliver it to the slot.
假设当前有4个slot连接到QPushButton::clicked(bool),当按钮被按下时,QT就把这个signal包装成一个 QEvent,放到消息队列里。QApplication::exec()或者线程的QThread::exec()会从消息队列里取消息,然后调用 signal关联的几个slot。这种方式既可以在线程内传递消息,也可以跨线程传递消息。
Qt::BlockingQueuedConnection
Same as QueuedConnection, except that the current thread blocks until the slot has been delivered. This connection type should only be used for receivers in a different thread. Note that misuse of this type can lead to dead locks in your application.
与Qt::QueuedConnection类似,但是会阻塞等到关联的slot都被执行。这里出现了阻塞这个词,说明它是专门用来多线程间传递消息的。
Qt::AutoConnection
If the signal is emitted from the thread in which the receiving object lives, the slot is invoked directly, as with Qt::DirectConnection; otherwise the signal is queued, as with Qt::QueuedConnection.
这种连接类型根据signal和slot是否在同一个线程里自动选择Qt::DirectConnection或Qt::QueuedConnection
这样看来,第一种类型的效率肯定比第二种高,毕竟第二种方式需要将消息存储到队列,而且可能会涉及到大对象的复制(考虑sig_produced(BigObject bo),bo需要复制到队列里)。
- Qt::ConnectionType 解析
- Qt::ConnectionType 解析
- Qt::ConnectionType 解析
- Qt::ConnectionType 解析
- Qt::ConnectionType 解析
- Qt::ConnectionType 解析
- Qt::ConnectionType 解析
- 信号和槽的连接类型 Qt::ConnectionType 解析
- qt connect Qt::ConnectionType介绍
- qt connect Qt::ConnectionType介绍
- qt的Qt::ConnectionType详细以及信号参数传递
- QT:moveToThread与信号与槽机制的第五个参数Qt::ConnectionType
- QT UI文件解析
- Qt源码解析(1)
- Qt解析xml
- 解析 Qt 内省机制
- qt xml 解析
- QT范例解析
- MQL5 命令行编译
- springmvc组件总结
- [docker]使用阿里云上面的私仓
- 算法-蓝桥杯习题(4-3)
- 启动系统安装程序开发指定文件,安装应用
- Qt::ConnectionType 解析
- validates的条件验证(if)的Proc用法
- 矩阵基础1010 UVA 11651 矩阵快速幂+DP 好题,推荐
- 有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student".
- Win8.1以及win10以上系统 安装msi文件方法
- 图片排序
- FZU 1911 矩阵快速幂
- 富文本编辑器CKEDITOR使用注意事项,Ajax回调
- Codeforces Round #301 (Div. 2) D. Bad Luck Island(概率DP)