[翻译] PySide6.QtCore.Qt.ConnectionType

翻译 (自用,不保证对)


PySide6.QtCore.Qt.ConnectionType

这个 enum 描述了 signals 和 slots 连接(connection) 的类型. 在一些特殊情况, 它决定了信号传递到插槽时的方式,比如 即时的(immediately)或 队列的(queued for delivery at a later time).


Constant Description
Qt.AutoConnection 默认方式,槽在信息号发送者的线程执行动作。(Default) If the receiver lives in the thread that emits the signal, is used. Otherwise, is used. The connection type is determined when the signal is emitted.
Qt.DirectConnection 槽立即在发送信号的线程,执行动作.
Qt.QueuedConnection 槽等到接收者的线程激活时,在接收者的线程内执行动作.
Qt.BlockingQueuedConnection 与上一个相同,不同在于,发送者的线程会阻塞(blocks),等待槽执行动作返回(returns). 注意:发送者和接收者不能在同一个线程,否则,线程会锁死(deadlock).
Qt.UniqueConnection 这个类型和以上的类型组合使用,用 OR 连接. 当这个类型被使用时, 如果这个信息与指定的槽已经建立了连接,connect() 不会有作用 (,比如, 同一个信号,重复连接同一个槽). 在Qt 4.6被引入.
Qt.SingleShotConnection 这个类型和以上的类型组合使用,用 OR 连接. 当这个类型被使用时,这个槽是一次性的,当信号发送到这个槽,槽会停止接收后续信息(broken). 在Qt 6.0被引入

当使用队列(queued)方式时,相关参数必须是QT可以接受的类型(types that are known to Qt’s meta-object system), 因为 Qt 要传递参数到后台的事件进程。如果你用队列方式时遇到以下错误:

QObject::connect: Cannot queue arguments of type 'MyType'

在connect()之前,先使用 qRegisterMetaType() 注册相关的数据类型.

在多线程用 信号和槽时, 查找 Signals and Slots Across Threads 的相关资料. (Queued Custom Type Example, QThread


See also:

connect() qRegisterMetaType() Q_DECLARE_METATYPE()

原文


PySide6.QtCore.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 Description
Qt.AutoConnection (Default) If the receiver lives in the thread that emits the signal, is used. Otherwise, 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 , 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 is set, 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.SingleShotConnection This is a flag that can be combined with any one of the above connection types, using a bitwise OR. When is set, the slot is going to be called only once; the connection will be automatically broken when the signal is emitted. This flag was introduced in Qt 6.0.

With queued connections, the parameters must be of types that are known to Qt’s meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message:

QObject::connect: Cannot queue arguments of type 'MyType'

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

When using signals and slots with multiple threads, see Signals and Slots Across Threads.


See also:

connect() qRegisterMetaType() Q_DECLARE_METATYPE()


posted @ 2022-03-12 14:58  方头狮  阅读(466)  评论(0)    收藏  举报