QProcessDeleter Class | Extending Qt Creator Manual
Description: A custom deleter for QProcess, used by QProcessTask.

- Extending Qt Creator Manual
- TaskTree
- QProcessDeleter
- Extending Qt Creator Manual 19.0.0

# QProcessDeleter Class

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

Header: | `#include <qprocesstask.h>`

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

Q_TASKTREE_EXPORT | operator()(QProcess *process)

## Static Public Members

Q_TASKTREE_EXPORT | syncAll()

## Detailed Description

QProcessDeleter 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 QProcessDeleter 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, QProcessDeleter::syncAll() should be called in order to synchronize all processes being still potentially finalized in separate thread. The call to QProcessDeleter::syncAll() is blocking in case some processes are still being finalized.

This strategy seems sensible, since when deleting the running QProcess via QProcessDeleter 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]` Q_TASKTREE_EXPORT QProcessDeleter::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 QProcessDeleter. The call should be executed from the main thread.

### Q_TASKTREE_EXPORT QProcessDeleter::operator()(QProcess *process)

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.