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/example/doric/engine/DoricTimerExtension.cpp
2021-05-20 18:27:45 +08:00

37 lines
881 B
C++

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