このページでは

QtTaskTree::Iterator Class

class QtTaskTree::Iterator

「For element」内でイテレータとして使用される基底クラス。詳細...

ヘッダー: #include <qtasktree.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS TaskTree)
target_link_libraries(mytarget PRIVATE Qt6::TaskTree)
qmake: QT += tasktree
以下のように: Qt 6.11
継承元:

QtTaskTree::ForeverIterator、QtTaskTree::ListIterator 、QtTaskTree::RepeatIterator 、およびQtTaskTree::UntilIterator

ステータス: テクノロジープレビュー

このクラスはテクノロジープレビュー段階にあり、変更される可能性があります。

注:このクラスのすべての関数は再入可能です。

パブリック関数

Iterator(QtTaskTree::Iterator &&other)
qsizetype iteration() const

詳細な説明

関連項目: For 、ForeverIterator 、RepeatIterator 、UntilIterator 、およびListIterator 。

メンバー関数のドキュメント

[constexpr noexcept default] Iterator::Iterator(QtTaskTree::Iterator &&other)

Iterator のインスタンスをMoveコンストラクタで生成します。

qsizetype Iterator::iteration() const

For (Iterator) >> 構文のDo 本体内で、現在実行中のハンドラの反復インデックスを返します。この関数は、レシピのDo 本体内に配置されたGroupItem 要素のハンドラ本体内からのみ使用してください。そうしないと、クラッシュする可能性があります。For 要素にIterator が確実に渡されていることを確認してください。

使用例:

constQList<std::chrono::seconds>timeouts={5s, 1s, 3s};
constListIterator iterator(timeouts);

const autoonSetup= [iterator](std::chrono::milliseconds &timeout) {
    timeout= *iterator;
    qDebug() << "Starting" << iterator.iteration() << "iteration with timeout"
            << *iterator << "秒";
};
const autoonDone= [iterator]{
    qDebug() << "Finished" << iterator.iteration() << "iteration with timeout"
            << *iterator << "秒。";
};

constGroup sequentialRecipe=For(iterator)>>Do {
    QTimeoutTask(onSetup,onDone)
};

constGroup parallelRecipe=For(iterator)>>Do {
    parallel,
    QTimeoutTask(onSetup,onDone)
};

sequentialRecipe を実行した際の出力は次のようになります:

Starting 0 iteration with timeout 5s seconds.
Finished 0 iteration with timeout 5s seconds.
Starting 1 iteration with timeout 1s seconds.
Finished 1 iteration with timeout 1s seconds.
Starting 2 iteration with timeout 3s seconds.
Finished 2 iteration with timeout 3s seconds.

逐次モードでは、doneハンドラ内の反復インデックスの順序が確実に保持されます。

parallelRecipe を実行した際の出力は次のようになります:

Starting 0 iteration with timeout 5s seconds.
Starting 1 iteration with timeout 1s seconds.
Starting 2 iteration with timeout 3s seconds.
Finished 1 iteration with timeout 1s seconds.
Finished 2 iteration with timeout 3s seconds.
Finished 0 iteration with timeout 5s seconds.

並列モードでは、doneハンドラにおける反復インデックスの順序が保持されることは保証されず、完了したタスクの順序に依存します。並列Do の本体内のdoneハンドラで返される反復インデックスは、対応するsetupハンドラにおける元の反復のインデックスと一致するため、後続のdoneハンドラにおける反復インデックスの順序は昇順ではない場合があります。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.