QML and Qt Quick
2020.11.03 22:25

QML과 코루틴(Coroutines)

조회 수 6850 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

function * 선언 (함수 키워드 뒤에 별표)은 Generator 객체를 반환하는 generator 함수를 정의한다. 다음의 피보나치 예제는 generator와 QML을 사용하여 코루틴의 예를 보여준다.

import QtQuick 2.11
import QtQuick.Window 2.11
import QtQuick.Controls 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Fibonacci")

    property var fibonacci: function* () {
        yield "0: 0"
        yield "1: 1"
        var f0 = 1, f1 = 0, n = 2;
        while (true) {
            var next = f1 + f0;
            f0 = f1;
            f1 = next;
            yield (n++) + ": " + (f0 + f1);
        }
    }

    Row {
        anchors.fill: parent
        Button {
            id: button
            property var coroutine: fibonacci()
            width: parent.width / 2; height: parent.height
            text: coroutine.next().value
            onPressed: text = coroutine.next().value
        }


        Button {
            text: "Reset!"
            width: parent.width / 2; height: parent.height
            onPressed: {
                button.coroutine = fibonacci()
                button.text = button.coroutine.next().value
            }
        }
    }
}

 

코루틴 이란?

코루틴(coroutine)은 루틴의 일종으로서, 협동 루틴이라 할 수 있다(코루틴의 "Co"는 with 또는 togather를 뜻한다). 상호 연계 프로그램을 일컫는다고도 표현가능하다. 루틴과 서브 루틴은 서로 비대칭적인 관계이지만, 코루틴들은 완전히 대칭적인, 즉 서로가 서로를 호출하는 관계이다. 코루틴들에서는 무엇이 무엇의 서브루틴인지를 구분하는 것이 불가능하다. 코루틴 A와 B가 있다고 할 때, A를 프로그래밍 할 때는 B를 A의 서브루틴으로 생각한다. 그러나 B를 프로그래밍할 때는 A가 B의 서브루틴이라고 생각한다. 어떠한 코루틴이 발동될 때 마다 해당 코루틴은 이전에 자신의 실행이 마지막으로 중단되었던 지점 다음의 장소에서 실행을 재개한다. 출처: 위키백과


  1. No Image notice

    Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서

    Date2019.01.05 CategoryQML and Qt Quick By운영자 Views161134
    read more
  2. No Image

    싱글 샷(Single-Shot) 시그널/슬롯 연결

    Date2021.05.12 CategoryQt 6 Bymakersweb Views8520
    Read More
  3. No Image

    응용프로그램 자동실행 설정 (on Windows)

    Date2021.05.08 CategoryC++ Class Bymakersweb Views6801
    Read More
  4. No Image

    Qt 6 에서 프로퍼티 바인딩

    Date2021.04.03 CategoryQt 6 Bymakersweb Views5872
    Read More
  5. No Image

    QML과 JavaScript 의 숫자 관련 내장된 함수

    Date2021.03.28 CategoryQML and Qt Quick Bymakersweb Views7700
    Read More
  6. Qt 5 코드를 Qt 6로 포팅하기 위해 도움이 되는 Clazy Framework

    Date2021.03.01 CategoryQt 6 Bymakersweb Views7274
    Read More
  7. C++로 작성한 클래스를 QML에서 생성

    Date2021.02.10 CategoryQML and Qt Quick Bymakersweb Views11401
    Read More
  8. Qt MQTT의 pus/sub 튜토리얼

    Date2021.02.06 CategoryMobile and Embedded Bymakersweb Views8468
    Read More
  9. Qt 를 사용하거나 기반으로 하는 응용프로그램

    Date2021.01.30 CategoryGeneral and Desktop Bymakersweb Views11610
    Read More
  10. No Image

    Loader를 사용하여 동적으로 QML 로드

    Date2021.01.19 CategoryQML and Qt Quick Bymakersweb Views9830
    Read More
  11. No Image

    QThread 및 QMutex 예제

    Date2021.01.12 CategoryC++ Class Bymakersweb Views8413
    Read More
  12. No Image

    그래픽 소프트웨어에서 디자인 내보내기 (Exporting Designs from Graphics Software)

    Date2020.12.25 CategoryQML and Qt Quick Byj2doll Views8007
    Read More
  13. No Image

    Qt5Compat 라이브러리를 사용하여 Qt5에서 Qt6로 포팅

    Date2020.12.05 CategoryQt 6 Bymakersweb Views6435
    Read More
  14. Qt Quick Controls 2에 네이티브 데스크탑 스타일 추가

    Date2020.11.23 CategoryQt 6 Bymakersweb Views10359
    Read More
  15. No Image

    QML 바인딩 끊김 진단

    Date2020.11.08 CategoryQML and Qt Quick Bymakersweb Views6890
    Read More
  16. No Image

    QML과 코루틴(Coroutines)

    Date2020.11.03 CategoryQML and Qt Quick Bymakersweb Views6850
    Read More
  17. No Image

    Qt 6의 비동기 API

    Date2020.10.19 CategoryQt 6 Bymakersweb Views6253
    Read More
  18. No Image

    QRandomGenerator 클래스를 사용하여 난수(random values) 생성

    Date2020.10.17 CategoryC++ Class Bymakersweb Views8135
    Read More
  19. No Image

    Qt 6에서 QList 변경사항

    Date2020.10.08 CategoryQt 6 Bymakersweb Views6844
    Read More
  20. No Image

    Qt 6.0의 개발 호스트 및 대상 플랫폼

    Date2020.09.16 CategoryQt 6 Bymakersweb Views11380
    Read More
  21. No Image

    main함수 명령줄 옵션 해석

    Date2020.09.01 CategoryC++ Class Bymakersweb Views9800
    Read More
Board Pagination Prev 1 2 3 4 5 9 Next
/ 9