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

可紊 提交于 2019-12-10 10:59:58

问题


I searched the internet but there is very little documentation available on BlackBerry 10 development. Is there something in BlackBerry 10 that allows you to run a function forever after specified intervals of time? Like there is NSTimer in iPhone/Objective-C that can run a function after every x minutes or so.


回答1:


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
        }
    }
]



回答2:


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()));



回答3:


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
}



回答4:


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.



来源:https://stackoverflow.com/questions/16457468/is-there-a-timer-in-blackberry-10-that-runs-your-functions-after-a-specified-tim

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