Is there a timer in BlackBerry 10 that runs your f

2019-05-20 20:59发布

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.

4条回答
做自己的国王
2楼-- · 2019-05-20 21:30

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()));
查看更多
Emotional °昔
3楼-- · 2019-05-20 21:32

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.

enter image description here

查看更多
We Are One
4楼-- · 2019-05-20 21:45

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
        }
    }
]
查看更多
Explosion°爆炸
5楼-- · 2019-05-20 21:48

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
}
查看更多
登录 后发表回答