Qt: Do events get processed in order?

安稳与你 提交于 2019-12-06 17:02:30

问题


If I had a class A, where one of its functions does:

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

Assuming that a class B has 2 slots, one connected to first_signal, and the other to second_signal, is it guaranteed that the slot that is connected to first_signal will always be processed before the second_signal slot?


回答1:


If you use direct connection type between signals and slots (Qt::DirectConnection) then the answer is yes.

From Qt help system:

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.

You can change default connection type to any of enum Qt::ConnectionType in QObject::connect method.



来源:https://stackoverflow.com/questions/1733022/qt-do-events-get-processed-in-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!