This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-Qt/doric/engine/timer_extension.cpp

28 lines
727 B
C++
Raw Normal View History

2019-12-14 10:04:17 +08:00
#include <QTimer>
2021-01-28 17:06:40 +08:00
#include "timer_extension.h"
#include "../utils/constant.h"
2019-12-14 10:04:17 +08:00
2021-01-28 17:06:40 +08:00
Q_INVOKABLE void TimerExtension::setTimer(long timerId, int time, bool repeat) {
2019-12-14 10:04:17 +08:00
QTimer *timer = new QTimer(this);
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, this, [=] () {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
} else {
2021-01-28 17:06:40 +08:00
this->method(timerId);
2019-12-14 10:04:17 +08:00
if (!repeat) {
deletedTimerIds->remove(timerId);
delete timer;
}
}
});
timer->start(time);
}
2021-01-28 17:06:40 +08:00
Q_INVOKABLE void TimerExtension::clearTimer(long timerId) {
2019-12-14 10:04:17 +08:00
deletedTimerIds->insert(timerId);
}