- Qt 6.12
- Qt TaskTree
- C++ Classes
- ListIterator
- Qt 6.12.0 Reference Documentation

# QtTaskTree::ListIterator Class

template <typename T> class QtTaskTree::ListIterator

The list iterator to be used inside For element. More...

Header: | `#include <qtasktree.h>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS TaskTree)` `target_link_libraries(mytarget PRIVATE Qt6::TaskTree)`
qmake: | `QT += tasktree`
Since: | Qt 6.11
Inherits: | QtTaskTree::Iterator
Status: | Technology preview

This class is in technology preview and is subject to change.

- List of all members, including inherited members

Note: All functions in this class are reentrant.

## Public Functions

| ListIterator(RangeGetter &&rangeGetter)
| ListIterator(const QList<T> &list)
const T & | operator*() const
const T * | operator->() const

## Detailed Description

The template parameter T specifies the element type of the list being iterated.

See also Iterator, ForeverIterator, RepeatIterator, and UntilIterator.

## Member Function Documentation

### `[explicit]` template <typename RangeGetter, typename RangeType = std::invoke_result_t<std::decay_t<RangeGetter>>> requires if_compatible_range<RangeGetter> ListIterator::ListIterator(RangeGetter &&rangeGetter)

Constructs the list iterator for the `For (ListIterator(rangeGetter)) >> Do {}` construct. The rangeGetter is a callable with no arguments returning a contiguous range whose `value_type` is `T`. The returned range does not need to be a QList<T>. Any contiguous range type supporting `std::data()` is accepted — for example, a getter returning QString is valid for `ListIterator<QChar>`. The getter called once when the Group containing this iterator is entered, with all relevant storages and parent iterations activated. The call might be skipped if the possible Group's onSetupHandler() returned a value other than SetupResult::Continue. The iterator will iterate over each element of the returned range.

This is a convenient pattern for iterating over nested loops:

     const ListIterator outer(QStringList{"12", "34"});
     const ListIterator inner([outer] { return *outer; });

     const Group recipe {
         For (outer) >> Do {
             For (inner) >> Do {
                 QSyncTask([inner] { qDebug() << *inner; })
             }
         }
     };

See also Iterator::iteration(), operator*(), and operator->().

### `[explicit]` ListIterator::ListIterator(const QList<T> &list)

Constructs the list iterator for the `For (ListIterator(list)) >> Do {}` construct. The iterator will iterate over each element from the passed list.

See also Iterator::iteration(), operator*(), and operator->().

### const T &ListIterator::operator*() const

Returns a reference to the current element inside a Do body. Use this function only from inside the handler body of any GroupItem element placed in the QtTaskTree::Do body of the recipe, otherwise you may expect a crash. Make sure that ListIterator is passed to the For element.

### const T *ListIterator::operator->() const

Returns a pointer to the current element inside a Do body. Use this function only from inside the handler body of any GroupItem element placed in the QtTaskTree::Do body of the recipe, otherwise you may expect a crash. Make sure that ListIterator is passed to the For element.