2018年10月30日
コメント
この記事は The Qt Blog の Playing with coroutines and QML を翻訳したものです。
執筆: Jesús Fernández, 2018年05月29日
(別名 コルーチンと Qt で遊んでみた パート2)
5747a7530206ac410b6bd7c1b8490d7d389ad3a5 により JavaScript Generators のサポートが QML に追加されました。これによって、前回の記事のフィボナッチ数列もジェネレーターで書けるようになりました。
サンプルコード:
import QtQuick 2.11
import QtQuick.Window 2.11
import QtQuick.Controls 2.2Window {
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);
}
}visible: true
width: 640
height: 480
title: qsTr("Fibonacci")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
}
}
}
}
素敵ですね!
最新リリースはこちらからダウンロードできます。 www.qt.io/download
Qt 6.10 がリリースされました!アプリケーション開発者やデバイス開発者向けに、多くの新機能と改善が追加されています。
現在、さまざまなポジションで採用を行っています。募集職種はこちら をご覧ください。また、Instagram をフォローして #QtPeople の働き方もぜひチェックしてください。
このブログは「Security advisory: Recently reported dr_wav issue impacts Qt」の抄訳です。..
記事を読む
このブログは「Congratulations Qt Champions 2025!」の抄訳です。 Qt プロジェクトを通して、Qt..
記事を読む
このブログは「Organizing ID-Based Translations with Labels in Qt Linguist」の抄訳です。..
記事を読む