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

标签 qt signals-slots

如果我有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/

相关文章:

android - 为 QLineEdit 选择输入键盘类型

c++ - Qt 即时响应键盘按下的键

Python - PyQt 信号 - 发出参数并将其发送到不同的类

python - PySide Slot Decorator 是必需的吗?

python - 使用列表作为参数定义 pyqt4 信号

c++ - 直接调用函数与发出信号(Qt - 信号和槽)

python - 为什么信号不发出?

c++ - CMake configure 无法在 Linux 上找到 Qt5

qt - 在 qmake 的 Makefile 中添加额外的变量

Qt - 信号槽中的参数