DtkCore
DTK Core module
dtimedloop.h
1/*
2 * Copyright (C) 2021 ~ 2021 UnionTech Technology Co., Ltd.
3 *
4 * Author: Wang Peng <[email protected]>
5 *
6 * Maintainer: Wang Peng <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21#ifndef DTIMEDLOOP_H
22#define DTIMEDLOOP_H
23#include <dtkcore_global.h>
24#include <DObject>
25
26#include <QEventLoop>
27
28DCORE_BEGIN_NAMESPACE
29
30class DObject;
31class DTimedLoopPrivate;
32class DTimedLoop : public QEventLoop, public DObject {
33 Q_OBJECT
34public:
35 explicit DTimedLoop() noexcept;
36 explicit DTimedLoop(QObject *parent) noexcept;
37
39
40 // 如果是 isRunning 则返回从开始到现在的 exec 执行时间,否则返回上次运行的时间
41 int runningTime();
42 void setTimeDump(bool flag = true);
43
44 void exit(int returnCode = 0);
45
46 // 方式1:不传定时时间,如果不退出就一直执行,配合 exit 使用
47 // 方式2:传入durationMs 参数的是定时执行的,也能调用 exit 提前退出
48 // 如果传入了 executionName 就会为本次执行设置一个名字,会输出到 log
49 // 在执行结束将会打印 exec 的执行时间,可以用 setTimeDump 控制其是否打印
50 int exec(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
51 int exec(int durationMs, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
52 int exec(const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
53 int exec(int durationMs, const QString &executionName, QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
54
55private:
56 Q_DISABLE_COPY(DTimedLoop)
57 D_DECLARE_PRIVATE(DTimedLoop)
58};
59
60DCORE_END_NAMESPACE
61
62#endif // DTIMEDLOOP_H
一些宏的定义.
Definition: dobject.h:38
Definition: dtimedloop.h:32