QT 第五个参数具体用法

QT官方文档描述如下

Constant Value Description
Qt::AutoConnection
0
(Default) If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted.
Qt::DirectConnection
1
The slot is invoked immediately when the signal is emitted. The slot is executed in the signalling thread.
Qt::QueuedConnection
2
The slot is invoked when control returns to the event loop of the receiver’s thread. The slot is executed in the receiver’s thread.
Qt::BlockingQueuedConnection
3
Same as Qt::QueuedConnection, except that the signalling thread blocks until the slot returns. This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock.
Qt::UniqueConnection
0x80
This is a flag that can be combined with any one of the above connection types, using a bitwise OR. When Qt::UniqueConnection is set, QObject::connect() will fail if the connection already exists (i.e. if the same signal is already connected to the same slot for the same pair of objects). This flag was introduced in Qt 4.6.

With queued connections, the parameters must be of types that are known to Qt’s meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message:

具体翻译内容如下

这个枚举用于信号与槽连接时的类型设定,它将确定将信号立即传递给槽函数还是存储在队列中后期传递。

Qt::AutoConnection
默认连接方式,规则如下:
1.信号与槽处于同一个线程中,使用Qt::DirectConnection模式
2.信号与槽处于不同线程中,使用Qt::QueuedConnection模式,

Qt::DirectConnection 槽函数立即被执行,且在发送信号的线程中执行,类似于函数回调,不可跨线程,也就是说如果信号的接收者在另一个线程,则不会被执行。

Qt::QueuedConnection 槽函数处理过程在接收者所在的线程中,且以队列的方式插入到事件循环里,需要接受者的事件循环执行到此事件槽函数才会被处理,对于信号发送的线程发送信号后不会阻塞,这种模式支持跨线程调用

Qt::BlockingQueuedConnection 和QueuedConnection类似,区别在于信号发送的线程会阻塞等待,直到槽函数执行完成,因此特别注意的禁止信号与槽处于同一线程中,会死锁。

Qt::UniqueConnection
这是一个标志,表示如果相同的信号与槽连接多次,则保证只能连接一次。什么意思?就是在正常的连接中,如果连接多次,则信号会被发送多次,同样槽函数也会被执行多次,为了避免只发送一次,可以将此标志和上述的四个连接类型使用 or运算联合使用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路过的小熊~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值