Цикл с задержкой в ​​Qml - PullRequest
0 голосов
/ 09 марта 2019

Я испробовал практически все решения из Интернета, но ничего не получалось.Я хочу создать цикл while (true) с задержкой около 20 мс на итерацию.

1 Ответ

1 голос
/ 09 марта 2019

Таймер будет лучше:

ApplicationWindow {
    id: window
    width: 320
    height: 260
    visible: true

    Timer {
        id: timer
        interval: 20
        running: false
        repeat: true
        property int returnedValue: 0
        onTriggered: {
            console.log("Loop iteration every 20ms");
            returnedValue = 12;
        }
        onReturnedValueChanged: {
            timer.stop();
            console.log("Stop loop wth:", returnedValue);
        }
    }

    function startTimer() {
        timer.running = true;
    }

    Button {
        text: "Click me"
        onClicked: startTimer()
    }
}
...