Is there a timer in BlackBerry 10 that runs your functions after a specified time interval?

三世轮回 提交于 2019-12-06 11:32:58

As pointed by @Sorry_Boss, you can use QTimer on C++ code. If you want to do that in QML, you can also register it for use in QML in the constructor of your app class, like this:

qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer");

Then, you can import it in your QML file:

import my.library 1.0

... and use it as an attached object to another component:

attachedObjects: [
    QTimer {
        id: timer
        interval: 1000 // 1 second
        onTimeOut {
            // do something
        }
    }
]

Use QTimer.

QTimer timer = new QTimer(this);
timer->start(intervalTime);

Connect timeout signal of timer with your function.

QObject::connect(timer, SIGNAL(timeout()), this,
            SLOT(yourFunction()));

Yes this can be done with QTimer

In cpp

QTimer *timer= new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);

void AppName::update(){
//Do operation on timeout
}

As a more general answer, because you will likely run into the same problem again, you have to treat BB10 as a completely different operating system and development environment because it is. Unlike the old environment though, the documentation is actually quite good. For example finding information on timers is as simple as going to the Cascades documentation site, selecting API Reference and typing 'timer' into the filter text box.

You will also find a wealth of help in the form of sample applications and general documentation and guidelines.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!