【问题标题】:How to make an infinite async loop on Plasma 5 plasmoids如何在 Plasma 5 等离子团上进行无限异步循环
【发布时间】:2019-08-08 20:51:19
【问题描述】:

我正在着手开发 KDE Plasma 5 plasmoid,我正在尝试制作一个 plasmoid,它每 10 秒从 API 获取数据并将其显示在标签中(来自 org.kde.plasma.components)。

在浏览器环境中,我们可以毫无问题地使用setTimeout,但是在这样的环境中,当这些功能不可用时该怎么办?

我试图在 Component.onCompleted 钩子上创建一个 while(true) 循环,但正如预期的那样,Plasmoid 没有加载,我的 CPU 发疯了。

import QtQuick 2.0
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras

Row {
    id: 'container'

    Component.onCompleted: {
        let counter = 0;

        while(true) {
            textContainer.text = counter;
            counter++;
        }
    }

    PlasmaComponents.Label {
        id: 'textContainer'
        text: ''
        width: 384
    }
}

【问题讨论】:

    标签: javascript asynchronous qml plasmoid kde-plasma


    【解决方案1】:

    它实际上比我想象的要简单得多,只是使用了Timer

    Timer {
        interval: 10000
        repeat: true
        running: true
        onTriggered: {
            // The code here
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 2017-12-12
      • 1970-01-01
      • 2021-12-12
      • 2020-05-11
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多