- Extending Qt Creator Manual
- QtTaskTree
- QProcessTaskDeleter
- Extending Qt Creator Manual 20.0.0-rc1

# QtTaskTree::QProcessTaskDeleter Class

class QtTaskTree::QProcessTaskDeleter

A custom deleter for QProcess, used by QProcessTask. More...

Header: | `#include <qprocesstask.h>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS TaskTree)` `target_link_libraries(mytarget PRIVATE Qt6::TaskTree)`
qmake: | `QT += tasktree`
Since: | 6.11

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

QtTaskTree::Q_TASKTREE_EXPORT | operator()(QProcess *process) const

## Static Public Members

QtTaskTree::Q_TASKTREE_EXPORT | syncAll()

## Detailed Description

QProcessTaskDeleter is used to enable fast destruction of running QProcess instances via QProcessTask in QTaskTree. Instead of deleting the running QProcess, which may block the caller's thread execution for a long time, the QProcessTaskDeleter moves the running QProcess into a separate thread and tries to finish it in a most gentle way. This consist of calling QProcess::terminate() with `500 ms` timeout, and if the process is still running after this timeout passed, the additional call to QProcess::kill() is performed.

Finally, on application quit, QProcessTaskDeleter::syncAll() should be called in order to synchronize all processes being still potentially finalized in separate thread. The call to QProcessTaskDeleter::syncAll() is blocking in case some processes are still being finalized.

This strategy seems sensible, since when deleting the running QProcess via QProcessTaskDeleter we don't block immediately, but postpone the possible (but not certain) block until the end of an application.

It is used by QProcessTask.

## Member Function Documentation

### `[static]` QtTaskTree::Q_TASKTREE_EXPORT QProcessTaskDeleter::syncAll()

This method should be called on application quit to synchronize the finalization of all still possibly running QProcess instances that were deleted before using QProcessTaskDeleter. The call should be executed from the main thread.

### QtTaskTree::Q_TASKTREE_EXPORT QProcessTaskDeleter::operator()(QProcess *process) const

Deletes the passed process in a most safe way. If the passed process is not running, it is deleted directly. Otherwise, it moves the process into a separate thread and tries to finish it in a most safe way by calling QProcess::terminate() with `500 ms` timeout, and if the process is still running after this timeout passed, the additional call to QProcess::kill() is performed.