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
2021-05-20 18:27:45 +08:00

28 lines
727 B
C++

#include <QTimer>
#include "timer_extension.h"
#include "../utils/constant.h"
Q_INVOKABLE void TimerExtension::setTimer(long timerId, int time, bool repeat) {
QTimer *timer = new QTimer(this);
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, this, [=] () {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
} else {
this->method(timerId);
if (!repeat) {
deletedTimerIds->remove(timerId);
delete timer;
}
}
});
timer->start(time);
}
Q_INVOKABLE void TimerExtension::clearTimer(long timerId) {
deletedTimerIds->insert(timerId);
}