1. 程式人生 > >Qt ---------- connect連接類型

Qt ---------- connect連接類型

this bin type() sta pes direct 接收 order 排隊

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.

直接連接的大概意思是:信號一旦發射,槽立即執行,並且槽是在信號發射的線程中執行的。

隊列連接的大概意思是:信號發射後,當事件循環返回到接收線程時槽函數就執行了,也就是說這種連接方式不是立即觸發槽函數的,而是要排隊等的,並且是在槽函數的線程中執行。


自動連接的大概意思是:信號發射對象如果和槽的執行對象在同一個線程,那麽將是直連方式,否則就是隊列方式。

阻塞隊列方式:在槽函數返回之前信號發射所在的線程都是阻塞的。

Call qRegisterMetaType() to register the data type before you establish the connection。

另外信號槽的參數必須是註冊的MetaType,所以當你使用自定義的類型或者 沒有註冊的類型,都要在connect連接語句前調用qRegisterMetaType()進行註冊,因為Qt需要保存你的參數。

Qt ---------- connect連接類型