Provides a way to run repetitive and single-shot timers. 更多...
Header: | #include <qul/timer.h> |
Since: | Qt Quick Ultralite 1.0 |
This class was introduced in Qt Quick Ultralite 1.0.
Timer (int interval = 0) | |
virtual | ~Timer () |
int | interval () const |
bool | isActive () const |
bool | isSingleShot () const |
void | onTimeout (FuncArg && f ) |
void | setInterval (int msec ) |
void | setSingleShot (bool singleShot ) |
void | start () |
void | start (int msec ) |
void | stop () |
Example with a C++11 lambda:
Qul::Timer timer; timer.onTimeout([]() { printf("triggered\n"); }); timer.start(1000); // will trigger every second
Example with a functor:
struct Functor { void operator()() { printf("triggered\n"); } }; Qul::Timer timer; timer.onTimeout(Functor()); timer.setSingleShot(true); timer.start(60000); // trigger once in a minute
Example in a QML object:
struct MinuteCounter : Qul::Object { Qul::Property<int> minutes; void start() { _countMinutes.onTimeout([this]() { minutes.set(minutes.get() + 1); }); _countMinutes.start(60000); } private: Qul::Timer _countMinutes; };
Instantiate a new timer.
One can specify the interval (default: 0). The default behavior for timers is to repeat. Use setSingleShot (true) to make it trigger only once.
The timer is not started automatically. Use start () to start it.
[virtual]
Timer::
~Timer
()
Automatically stops the timer
Returns the interval
另请参阅 setInterval .
Returns true if the timer is running (pending); otherwise returns false
返回
True
for single shot timers or
False
否则。
另请参阅 setSingleShot .
Set a callable object as a callback.
自变量 f must be a callable object such as a lambda or std::function or any struct with an operator().
It will be called every time the timer triggers.
When calling this function several times, only the last callback stays active.
另请参阅 start and setSingleShot .
Sets the timeout interval in milliseconds to msec
Setting the interval of an active timer does not change the next event.
另请参阅 interval .
Set whether the timer is a singleShot timer.
单发计时器仅激发一次,非单发定时器被激发每隔 interval 毫秒。
默认值为
False
.
另请参阅 isSingleShot .
Starts or restart the timer
If the timer is already running, it will be stopped and restarted.
If singleShot is true, the timer will be activated only once.
另请参阅 stop .
Starts or restarts the timer with a timeout interval of msec milliseconds
If the timer is already running, it will be stopped and restarted.
If singleShot is true, the timer will be activated only once.
另请参阅 stop .
停止计时器。
另请参阅 start .