이 페이지에서

QtTaskTree::Do Class

class QtTaskTree::Do

For 및 When 구문과 함께 사용되는 본문 요소입니다. 더 보기...

헤더: #include <qtasktree.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS TaskTree)
target_link_libraries(mytarget PRIVATE Qt6::TaskTree)
qmake: QT += tasktree
다음부터: Qt 6.11부터
상태: 기술 미리보기

이 클래스는 기술 미리보기 단계에 있으며 변경될 수 있습니다.

참고: 이 클래스의 모든 함수는 재진입 가능합니다.

공개 함수

Do(const QtTaskTree::GroupItems &children)
Do(std::initializer_list<QtTaskTree::GroupItem> children)
Do(QtTaskTree::Do &&other)
QtTaskTree::Group operator>>(const QtTaskTree::When &whenItem, const QtTaskTree::Do &doItem)

상세 설명

For 의 각 반복에서 또는 When 의 배리어가 진행된 후에 실행될 작업 목록을 포함하는 본문 요소입니다.

For (RepeatIterator(5)) >> Do {
    task1,
    task2
};

For 루프의 경우, Do의 본문이 여러 번 실행됩니다. onGroupSetup() 또는 onGroupDone() 핸들러가 Do의 생성자에 전달된 자식 객체의 일부인 경우, 전체 루프가 시작되기 전과 전체 루프가 끝난 후에 한 번씩만 실행됩니다.

const RepeatIterator iterator(3);

const auto onSetup = [] { qDebug() << "Setup"; };

const auto onSync = [iterator] { qDebug() << "Current iteration:" << iterator->iteration(); };

const auto onDone = [] { qDebug() << "Done"; };

const Group recipe = For (iterator) >> Do {
    onGroupSetup(onSetup),
    QSyncTask(onSync),
    onDone(onDone)
};

위의 코드를 실행하면 다음과 같은 결과가 출력됩니다:

Setup
Current iteration: 0
Current iteration: 1
Current iteration: 2
Done

각 반복마다 그룹 핸들러를 호출하려는 경우, 다음과 같이 Do 본문을 추가적인 Group 로 감싸십시오:

const Group recipe = For (iterator) >> Do {
    Group {
        onGroupSetup(onSetup),
        QSyncTask(onSync),
        onDone(onDone)
    }
};

후자의 예제를 실행하면 다음과 같은 결과가 출력됩니다:

Setup
Current iteration: 0
Done
Setup
Current iteration: 1
Done
Setup
Current iteration: 2
Done

Storage 가 본문의 직접 자식으로 전달될 때도 비슷한 현상이 발생합니다. 저장 구조체는 전체 루프가 시작되기 전에 단 한 번만 인스턴스화되며, 전체 루프가 끝난 직후에 소멸됩니다. 각 반복마다 Storage 의 별도 인스턴스를 갖도록 하려면, Do 본문을 추가적인 Group 로 감싸야 합니다.

For 루프의 Do 본문에 parallel 요소를 배치할 때는 주의해야 합니다. 모든 반복이 병렬로 시작되기 때문입니다. 특히 ForeverIterator 의 경우, 이는 바람직하지 않을 수 있습니다.

For 및 When도 참조하십시오 .

멤버 함수 문서

[explicit] Do::Do(const QtTaskTree::GroupItems &children)

각 For 의 반복마다, 또는 When 의 배리어가 진행된 후에 실행될 children 를 가진 Do 본문을 생성합니다.

[explicit] Do::Do(std::initializer_list<QtTaskTree::GroupItem> children)

children 를 초기화 목록으로 전달하여 Do 본문을 생성합니다.

이 함수는 오버로드된 함수입니다.

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

Do 의 인스턴스를 생성합니다.

관련 비멤버

QtTaskTree::Group operator>>(const QtTaskTree::When &whenItem, const QtTaskTree::Do &doItem)

whenItem 와 doItem 바디를 결합하여, 태스크 트리 레시피에서 바로 사용할 수 있는 Group 를 반환합니다.

© 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.