对QT 的信号连接类型的理解

这几天各种纠结于QT信号和槽的机制,对于connect的五个参数的理解,今天有了一点新的认识。

下面先贴出一下QT assistance上的描述


Qt::AutoConnection(default) 

If the signal is emitted from a different thread than the receiving object, the signal is queued, behaving as Qt::QueuedConnection. Otherwise, the slot is invoked directly, behaving as Qt::DirectConnection. The type of connection is determined when the signal is emitted.


Qt::DirectConnection

The slot is invoked immediately, when the signal is emitted.

注意使用这个连接方式的时,它是直接调用,会阻塞直到slot执行完毕,执行环境当然是在调用线程中。

如果在别的线程中使用这种方式的连接来创建窗口这是不允许的,只能在qapplication的事件循环中创建。

Qt::QueuedConnection

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

Same as QueuedConnection, except the current thread blocks until the slot returns. This connection type should only be used where the emitter and receiver are in different threads.



Note: Violating this rule can cause your application to deadlock.


Qt::UniqueConnection

Same as AutoConnection, but the connection is made only if it does not duplicate an existing connection. i.e., if the same signal is already connected to the same slot for the same pair of objects, then the connection will fail. This connection type was introduced in Qt 4.6。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值