classPiiEventProcessor
#include <PiiEventProcessor.h>
A home-made event loop.
Inherits QThread
Inherited by PiiEventProcessorRunner
Description
PiiEventProcessor is useful if the main thread of an application is not controlled by Qt. Since event delivery depends on the existence of a QCoreApplication instance, one needs to create a separate thread that plays the role of a main thread and instantiates QCoreApplication.
When started, PiiEventProcessor creates a new instance of QCoreApplication if one does not already exist, and enters its event loop. All subsequent instances of PiiEventProcessor enter a thread-specific event loop. The main thread must not be stopped until all other threads have finished their execution.
// In a non-Qt thread QObject* obj = new QObject; PiiEventProcessor p; p.start(); p.takeObject(obj); // do whatever needed p.stop(); delete obj;
Note that PiiEventProcessor also works with ordinary Qt applications. In such a case, QCoreApplication will not be instantiated again, and run() always enters a thread-specific event loop.
Constructors and destructor
|
Create a new PiiEventProcessor instance. |
Public member functions
|
void
|
( )
Start the event loop in a new thread. |
|
void
|
( )
Stops the thread. |
|
void
|
Move an object to this thread's event loop. |
Static public member functions
|
static void
|
Move |
Protected member functions
|
void
|
( )
Instantiates QCoreApplication if one does not already exist, and enters the an event loop. |
Function details
-
PiiEventProcessor
()[inline]Create a new PiiEventProcessor instance.
-
void startThread
()Start the event loop in a new thread.
Please do not call QThread::start() directly. If you do, the thread exits immediately.
-
void stop
()Stops the thread.
Calls QCoreApplication::exit() if this is the main thread. Otherwise calls QThread::exit().
-
void takeObject
Move an object to this thread's event loop.
This is a work-around for a Qt bug that causes a crash when moving an object from a non-Qt thread. Use this function to enable event processing for objects created in a non-Qt thread.
See also
-
Move
objtothread.This is a work-around for a Qt bug that causes a crash when trying to move an object away from a non-Qt thread (fixed in 4.2). Use this function to enable event processing for objects created in a non-Qt thread. The function calls obj->moveToThread() if the object is already owned by a QThread. In this case, the restrictions of QObject::moveToThread() apply. Otherwise, this function is only ensured to work if
-
objhas no parent (it may have children, though). -
there are no pending events for
obj -
the target thread's event loop is not processing an event (the event loop is empty).
-
-
void run
()[protected]Instantiates QCoreApplication if one does not already exist, and enters the an event loop.
Deletes the QCoreApplication instance once the thread finishes, if one was created.
Add a note
Not a single note added yet. Be the first, add yours.