Workspace 6.21.5
|
Start a task in a specific thread and wait for a task finished signal. More...
#include <Workspace/Application/System/signaldrivenblockingtask.h>
Public Types | |
enum | State { Running , Aborted , Finished } |
Signals | |
void | taskAborted () |
void | taskFinished () |
Signals inherited from BlockingTask | |
void | performTask (bool *result) |
Public Member Functions | |
bool | doTaskAndAwaitSignal () |
State | state () const |
Public Member Functions inherited from BlockingTask | |
~BlockingTask () override | |
bool | doTask () |
Protected Slots | |
void | onTaskAborted () |
void | onTaskFinished () |
Protected Slots inherited from BlockingTask | |
virtual void | taskWrapper (bool *result) |
Protected Member Functions | |
SignalDrivenBlockingTask (QThread *homeThread=QThread::currentThread()) | |
~SignalDrivenBlockingTask () override | |
Protected Member Functions inherited from BlockingTask | |
BlockingTask (QThread *homeThread=QThread::currentThread()) | |
QSemaphore & | semaphore () |
virtual bool | task ()=0 |
Additional Inherited Members | |
Static Public Member Functions inherited from BlockingTask | |
static bool | doTask (std::function< bool()> &&work, QThread *homeThread=QCoreApplication::instance() ->thread()) |
This class is similar to a BlockingTask, but rather than returning as soon as the task is finished, it waits for the taskFinished signal to be emitted before returning. This makes it suitable for tasks such as running a modeless dialog box where the execution thread needs to be blocked while awaiting a response, yet the gui thread should remain responsive.
This is not suitable for blocking the calling thread, as the calling thread would not be able to unblock it. In this case, the task would return straight away - you can test for this as the state would be Running rather than Finished or Aborted
The user is responsible for ensuring that the taskFinished (or taskAborted) signal is emitted: if not, the home thread is paused indefinitely. For example, in the case of a dialogue box where the execution thread is waiting for a response, you could create a modeless dialog box in task() and connect the QDialog accepted or finished signal to the SignalDrivenBlockingTask taskFinished signal
enum State |
|
protected |
|
overrideprotected |
The destructor should never be invoked while there is a running task.
bool doTaskAndAwaitSignal | ( | ) |
|
protectedslot |
This should be emitted to indicate that the home thread should be unblocked even though the task did not finish properly.
|
protectedslot |
This (or taskAborted) must be emitted to indicate that the task has finished and that the home thread should be unblocked.
SignalDrivenBlockingTask::State state | ( | ) | const |
|
signal |
Emit this rather than task finished to indicate that the home thread should be unblocked even though the task did not finish normally.
|
signal |
This (or taskAborted) must be emitted to indicate that the task has finished and that the home thread should be unblocked.