enum Qt::ConnectionType
This enum describes the types of connection that can be used between signals and slots. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time.
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. |
以下是我的个人的学习理解(翻译)
这个集合描述了用在信号和槽函数之间的连接方式。尤其决定了信号被发送给槽函数是否立即执行或者延时执行。
Constant | Value | Description |
Qt::AutoConnection | 0 | 自动连接,即默认连接,如果接受者和信号发送者在同一线程,使用Qt::DirectConnection直接连接方式,否则使用Qt::QueuedConnection队列连接方式。连接类型取决于信号发送的时候。 |
Qt::DirectConnection | 1 | 直接连接,当信号发射后立即执行槽函数,槽函数和信号在同一个线程执行。 |
Qt::QueuedConnection | 2 | 队列连接,槽函数在接收者的线程事件循环返回后取得控制权,槽函数在接收者的线程中执行。意思应该是说接收部件所在的线程的事件循环返回后再执行槽,无论槽执行与否,发射信号处后面的代码都会立即执行。 |
Qt::BlockingQueuedConnection | 3 | 阻塞队列连接,像Qt::QueuedConnection一样,除非信号线程阻塞直到槽函数返回,如果接收者在信号所在线程中,该连接方式不能使用,或者应用程序将会死锁。 |
Qt::UniqueConnection | 0x80 | 这个标志能被上面的任何一个连接方式进行组合,使用按位或,当Qt::UniqueConnection被设置,如果连接已经存在(如果在一组对象中相同的信号已经连接相同的槽函数),QObject::connect()连接将会失败。这个标志在Qt4.6中被引入。 |