Abstract base class for long running background tasks.
Tasks can be controlled directly, or added to a QgsTaskManager for automatic management.
Derived classes should implement the process they want to execute in the background within the run() method. This method will be called when the task commences (ie via calling run() ).
Long running tasks should periodically check the isCanceled() flag to detect if the task has been canceled via some external event. If this flag is true
then the task should clean up and terminate at the earliest possible convenience.
- Since
- QGIS 3.0
Definition at line 54 of file qgstaskmanager.h.
Adds a subtask to this task.
Subtasks allow a single task to be created which consists of multiple smaller tasks. Subtasks are not visible or indepedently controllable by users. Ownership of the subtask is transferred. Subtasks can have an optional list of dependent tasks, which must be completed before the subtask can begin. By default subtasks are considered independent of the parent task, ie they can be run either before, after, or at the same time as the parent task. This behavior can be overridden through the subTaskDependency argument. Note that subtasks should NEVER be dependent on their parent task, and violating this constraint will prevent the task from completing successfully.
The parent task must be added to a QgsTaskManager for subtasks to be utilized. Subtasks should not be added manually to a QgsTaskManager, rather, only the parent task should be added to the manager.
Subtasks can be nested, ie a subtask can legally be a parent task itself with its own set of subtasks.
Definition at line 155 of file qgstaskmanager.cpp.
Notifies the task that it should terminate.
Calling this is not guaranteed to immediately end the task, rather it sets the isCanceled() flag which task subclasses can check and terminate their operations at an appropriate time. Any subtasks owned by this task will also be canceled. Derived classes must ensure that the base class implementation is called from any overridden version.
- See also
- isCanceled()
Reimplemented in QgsVectorWarperTask, QgsMapRendererTask, QgsNetworkContentFetcherTask, QgsPointCloudLayerExporterTask, QgsProcessingAlgRunnerTask, QgsProviderSublayerTask, QgsProxyProgressTask, QgsVectorFileWriterTask, QgsVirtualLayerTask, QgsRasterFileWriterTask, QgsVectorLayerExporterTask, and QgsVectorLayerFeatureCounter.
Definition at line 91 of file qgstaskmanager.cpp.
virtual void QgsTask::finished |
( |
bool |
result | ) |
|
|
inlineprotectedvirtual |
virtual bool QgsTask::run |
( |
| ) |
|
|
protectedpure virtual |
Performs the task's operation.
This method will be called when the task commences (ie via calling start() ), and subclasses should implement the operation they wish to perform in the background within this method.
A task must return a boolean value to indicate whether the task was completed successfully or terminated before completion.
Implemented in QgsVectorWarperTask, QgsMapRendererTask, QgsNetworkContentFetcherTask, QgsPointCloudLayerExporterTask, QgsProcessingAlgRunnerTask, QgsProviderSublayerTask, QgsCopyFileTask, QgsProxyProgressTask, QgsVectorFileWriterTask, QgsVirtualLayerTask, QgsRasterFileWriterTask, QgsVectorLayerExporterTask, and QgsVectorLayerFeatureCounter.
bool QgsTask::waitForFinished |
( |
int |
timeout = 30000 | ) |
|
Blocks the current thread until the task finishes or a maximum of timeout milliseconds.
If timeout is 0
the thread will be blocked forever. In case of a timeout, the task will still be running. In case the task already is finished, the method will return immediately while returning \c true
.
The result will be false
if the wait timed out and true
in any other case.
Definition at line 168 of file qgstaskmanager.cpp.