gpt4 book ai didi

qt - Qt:事件是否按顺序处理?

转载 作者:行者123 更新时间:2023-12-03 12:55:47 27 4
gpt4 key购买 nike

如果我有A类,那么它的功能之一是:

void A::func()
{
emit first_signal();
emit second_signal();
}

假设B类有2个插槽,一个插槽连接到 first_signal,另一个插槽连接到 second_signal,是否可以保证在到 first_signal插槽之前,始终处理 来处理连接到second_signal的插槽?

最佳答案

如果在信号和插槽之间使用直接连接类型(Qt::DirectConnection),则答案是肯定的。

从Qt帮助系统:

When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal function call. When this happens, the signals and slots mechanism is totally independent of any GUI event loop. Execution of the code following the emit statement will occur once all slots have returned. The situation is slightly different when using queued connections; in such a case, the code following the emit keyword will continue immediately, and the slots will be executed later.



您可以使用 enum Qt::ConnectionType方法将默认连接类型更改为 QObject::connect中的任何一种。

关于qt - Qt:事件是否按顺序处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1733022/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com