【QT】QT::QueuedConnection Connect语句的五个参数

在阅读代码时遇到了有五个参数的connect语句,于是去查找QT Assistant,发现其实他本来就是五个参数,只是平时第五个参数采用缺省参数而不显示。
第五个参数列表:
enum Qt::ConnectionType

Constant Description
Qt::AutoConnection (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 The slot is invoked immediately when the signal is emitted. The slot is executed in the signalling thread.
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 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 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.

机翻:

常数
价值
描述
Qt: AutoConnection
0
(默认)如果接收器位于发出信号的线程中,则使用Qt::DirectConnection。否则,使用Qt::QueuedConnection。连接类型是在信号发出时确定的。
Qt: DirectConnection
1
当信号发出时,立即调用插槽。槽在信号线程中执行。
Qt: QueuedConnection
2
当控制返回到接收方线程的事件循环时,将调用该槽。插槽在接收方的线程中执行。
Qt: BlockingQueuedConnection
3.
与Qt::QueuedConnection相同,除了信号线程阻塞直到槽返回。如果接收方处于发送信号的线程中,则不能使用此连接,否则应用程序将死锁。
Qt: UniqueConnection
0 x80
这是一个可以使用按位或与上述任何一种连接类型组合的标志。当Qt::UniqueConnection被设置时,如果连接已经存在,QObject::connect()将会失败(也就是说,如果相同的信号已经连接到相同的槽上,对应于相同的对对象)。在Qt 4.6中引入了这个标志。

猜你喜欢

转载自blog.csdn.net/Flywithdawn/article/details/109080263
今日推荐