How to call a function from one thread on a QObject in another thread.
- The most basic operation is to post an event to the object in the other thread. The event loop in the target objects thread will then deliver the event to the target object. See the documentation [doc.qt.nokia.com].
- The second approach is to make use of Qt’s queued connections. This is also implemented in terms of the first method, and works for any target object that has an event loop running in the thread that owns it. One can either specify a queued connection by passing the parameter Qt::QueuedConnection [doc.qt.nokia.com]to the connect statement or use Qt::AutoConnection, the default, which decides at runtime how the slot should be called. See the documentation [doc.qt.nokia.com]
- Another way is using QMetaObject::invokeMethod()
本文介绍了如何在Qt中通过事件处理和队列连接从一个线程调用另一个线程的对象函数。包括基本操作、使用事件循环、队列连接方法及QMetaObject::invokeMethod()的实现。
3978

被折叠的 条评论
为什么被折叠?



