对QT 的信号连接类型的理解
2013-04-25 12:56
218 查看
这几天各种纠结于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。
下面先贴出一下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。
相关文章推荐
- Qt- “信号-槽”机制之连接类型 部分文档翻译
- 信号和槽的连接类型 Qt::ConnectionType 解析
- Qt信号和槽连接方式的选择
- Qt多线程间信号槽传递非QObject类型对象的参数
- Qt中除了用connect可以连接信号和槽之外还有什么方法可以连接
- Qt多个信号连接到一个槽,在槽中识别信号的发送者方法
- Qt5 UI信号、槽自动连接的控件重名大坑
- Qt学习:线程间共享数据(使用信号槽传递数据,必须提前使用qRegisterMetaType来注册参数的类型)
- 关于Qt信号/槽的参数类型
- QT信号槽连接方式
- QT自定义Action的信号和槽连接问题
- Qt信号槽连接在有默认形参下的情况思考
- 信号槽传递非Qt库类型参数时,出现QObject::connect: Cannot queue arguments of type 'QUuid'(Make sure 'string' is regi
- Qt编程技巧 多个信号连接一个槽
- QT中代码中与设计器中控件信号与SLOT连接
- QT 信号与槽有连接 槽未响应
- Qt多线程间信号槽传递非QObject类型对象的参数
- 连接信号与响应函数---QT
- Qt 信号槽连接方式
- qt学习第五课:深入理解信号和槽