Qt 中 "event loop" w.r.t 线程这个术语是什么意思?
What is the meaning of the term "event loop" w.r.t threads in Qt?
http://doc.qt.io/qt-5/threads-qobject.html#per-thread-event-loop
https://wiki.qt.io/Threads_Events_QObjects#Per-thread_event_loop
这两个链接讲的是事件循环。请解释Qt中"event loop"w.r.t线程的"meaning"?
事件循环通常是由主线程 运行 接收来自系统(例如 GUI 交互、网络事件、计时器...)或来自其他 Qt 的事件的循环组件(例如 QCoreApplication::postEvent()
, ...). The event loop waits for new events to arrive in the event queue, then takes them out of the queue and sends them to their destination QObject
where they are handled by an overridden QObject::event(QEvent*)
(e.g. A QPushButton
would handle a mouse press event by emitting pressed()
,...)。
每线程事件循环是上述概念的概括。这使得通过引入 QObject
的 thread affinity 的概念在工作线程中处理事件成为可能。线程关联是特定 QObject
应该在其中处理其事件的线程(从中调用 QObject::event
的线程 QObject
)。从总体上看,这可以用于工作线程中的 运行 异步代码(因为 GUI 代码应该 运行 仅在主线程中)。例如,您可以 运行 许多异步套接字,并有 QTimer
s 在某个指定的不活动时间后断开这些套接字,所有这些都在单个工作线程中。每线程事件循环对于跨线程信号槽连接也是必不可少的,因为这种信号发射在引擎盖下被转换为 QMetaCallEvent
s(将被传送到它的目的地 QObject
)。
http://doc.qt.io/qt-5/threads-qobject.html#per-thread-event-loop
https://wiki.qt.io/Threads_Events_QObjects#Per-thread_event_loop
这两个链接讲的是事件循环。请解释Qt中"event loop"w.r.t线程的"meaning"?
事件循环通常是由主线程 运行 接收来自系统(例如 GUI 交互、网络事件、计时器...)或来自其他 Qt 的事件的循环组件(例如 QCoreApplication::postEvent()
, ...). The event loop waits for new events to arrive in the event queue, then takes them out of the queue and sends them to their destination QObject
where they are handled by an overridden QObject::event(QEvent*)
(e.g. A QPushButton
would handle a mouse press event by emitting pressed()
,...)。
每线程事件循环是上述概念的概括。这使得通过引入 QObject
的 thread affinity 的概念在工作线程中处理事件成为可能。线程关联是特定 QObject
应该在其中处理其事件的线程(从中调用 QObject::event
的线程 QObject
)。从总体上看,这可以用于工作线程中的 运行 异步代码(因为 GUI 代码应该 运行 仅在主线程中)。例如,您可以 运行 许多异步套接字,并有 QTimer
s 在某个指定的不活动时间后断开这些套接字,所有这些都在单个工作线程中。每线程事件循环对于跨线程信号槽连接也是必不可少的,因为这种信号发射在引擎盖下被转换为 QMetaCallEvent
s(将被传送到它的目的地 QObject
)。