信号执行顺序与Qt :: QueuedConnection [英] Signal execution order with Qt::QueuedConnection
问题描述
我有两个信号A和B从线程X中的对象一个接一个地发出,并且两个连接的插槽在主线程中。连接是QueuedConnection(由于多线程连接)。我的问题是:在调用插槽时尊重的信号的顺序,还是有可能以任意顺序执行它们?
I have two signals A and B emitted one after another from an object in thread X, and the two connected slots are in the Main thread. The connection is QueuedConnection (due to multithreading connect). My question is: is the order of the signals respected in their call to the slots, or is there a chance for them to be executed in an arbitrary order?
推荐答案
两个信号都将在X线程的单个事件队列中排队,因此将按照发出信号的顺序执行相应的插槽。
Both of your signals will be queued in a single event queue of the X thread, so corresponding slots will be executed in the order of signals were emitted.
但是在下面的情况下,你不能依赖插槽执行顺序:
But in the following case you can't rely on the slots execution order:
signal A connected to a slot in X thread
signal B connected to a slot in Y thread
Qt :: BlockingQueuedConnection
连接类型。如果你使用它连接你的第一个信号,你的当前线程将被阻塞,直到另一个线程中的相应插槽完成它的工作。
Also, there is a Qt::BlockingQueuedConnection
connection type. If you connect your first signal using it, your current thread will be blocked until the corresponding slot in another thread finishes its job.
这篇关于信号执行顺序与Qt :: QueuedConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!