QtTaskTree::If Class | Extending Qt Creator Manual
Description: An "if" element used in conditional expressions.

- Extending Qt Creator Manual
- TaskTree
- If
- Extending Qt Creator Manual 19.0.0

# QtTaskTree::If Class

class QtTaskTree::If

An "if" element used in conditional expressions. More...

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

Note: All functions in this class are reentrant.

## Detailed Description

An initial condition element of the conditional expressions. Must always be followed by Then element.

The conditional expressions in the TaskTree module enable processing of branch conditions and their bodies in an asynchronous way. For example:

     const Group recipe {
         If (conditionTask1) >> Then {
             bodyTask1
         } >> ElseIf (conditionTask2) >> Then {
             bodyTask2
         } >> Else {
             bodyTask3
         }
     };

When the above recipe is run with QTaskTree, the task tree starts the asynchronous `conditionTask1` first. After it's finished, depending on the result, the task tree may either execute the `bodyTask1` when the `conditionTask1` finished with success, or dispatch another condition by executing `conditionTask2` otherwise. In case the `bodyTask1` is executed, no other tasks are executed, and the result of `bodyTask1` is the final result of the whole conditional expression.

See also Then, Else, and ElseIf.