c++qtevent-loopqeventloop

QCoreApplication::processEvents - why must it be called from main thread only?


Since there is only one QCoreApplication object, why does it matter from which thread QCoreApplication::processEvents() is called?

After all, the threads all share the same address space.


Solution

  • Your title is not true. Probably you are assuming QCoreApplication::processEvents is a system-wide "process all possible events of all threads" call, which it is not. You can call it from any thread you are in (and which is running an event loop).

    Why does it matter from which thread it is called: In Qt the event loop is a per-thread resource (you can run own event loop on any thread) and QCoreApplication::processEvents processes event queue of the current thread.