【QT】QT::QueuedConnection Connect語句的五個引數

2020-10-16 17:00:25

在閱讀程式碼時遇到了有五個引數的connect語句,於是去查詢QT Assistant,發現其實他本來就是五個引數,只是平時第五個引數採用預設引數而不顯示。
第五個參數列:
enum Qt::ConnectionType

ConstantDescription
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::DirectConnectionThe slot is invoked immediately when the signal is emitted. The slot is executed in the signalling thread.
Qt::QueuedConnectionThe 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::BlockingQueuedConnectionSame 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::UniqueConnectionThis 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中引入了這個標誌。