DtkCore
DTK Core module
载入中...
搜索中...
未找到
dtimedloop.h
1// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DTIMEDLOOP_H
6#define DTIMEDLOOP_H
7#include <dtkcore_global.h>
8#include <DObject>
9
10#include <QEventLoop>
11
12DCORE_BEGIN_NAMESPACE
13
14class DObject;
15class DTimedLoopPrivate;
16class DTimedLoop : public QEventLoop, public DObject {
17 Q_OBJECT
18public:
19 explicit DTimedLoop() noexcept;
20 explicit DTimedLoop(QObject *parent) noexcept;
21
23
24 // 如果是 isRunning 则返回从开始到现在的 exec 执行时间,否则返回上次运行的时间
25 int runningTime();
26 void setTimeDump(bool flag = true);
27
28 void exit(int returnCode = 0);
29
30 // 方式1:不传定时时间,如果不退出就一直执行,配合 exit 使用
31 // 方式2:传入durationMs 参数的是定时执行的,也能调用 exit 提前退出
32 // 如果传入了 executionName 就会为本次执行设置一个名字,会输出到 log
33 // 在执行结束将会打印 exec 的执行时间,可以用 setTimeDump 控制其是否打印
34 int exec(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
35 int exec(int durationMs, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
36 int exec(const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
37 int exec(int durationMs, const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
38
39private:
40 Q_DISABLE_COPY(DTimedLoop)
41 D_DECLARE_PRIVATE(DTimedLoop)
42};
43
44DCORE_END_NAMESPACE
45
46#endif // DTIMEDLOOP_H
Definition dobject.h:25
Definition dtimedloop.h:16