Reputation: 4970
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.
Upvotes: 2
Views: 2086
Reputation: 5472
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.
Upvotes: 3
Reputation: 24231
If you're seeing this warning it is because code inside the processEvents
is not thread-safe. Even though they share the same address space, work or data could be accumulated in a state on one thread, then the thread may be interrupted, the state could be modified by another thread, and then the original thread will resume its process as if the original state was still valid, but now it isn't. You could lose data or corrupt memory if you were doing things like modifying a linked list or any non-threadsafe data structure, among other hazards.
Upvotes: 0