2019-10-14 02:24:26 +00:00
|
|
|
|
#ifndef SAVERUNTIME_H
|
|
|
|
|
#define SAVERUNTIME_H
|
|
|
|
|
|
2021-09-26 01:50:09 +00:00
|
|
|
|
/**
|
|
|
|
|
* 运行时间记录 作者:feiyangqingyun(QQ:517216493) 2016-12-16
|
|
|
|
|
* 1. 可以启动和停止服务,在需要的时候启动。
|
|
|
|
|
* 2. 可以指定日志文件存放目录。
|
|
|
|
|
* 3. 可以指定时间日志输出间隔。
|
|
|
|
|
* 4. 可以单独追加一条记录到日志文件。
|
|
|
|
|
* 5. 日志为文本格式,清晰明了。
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-14 02:24:26 +00:00
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QDateTime>
|
2021-10-07 02:57:25 +00:00
|
|
|
|
|
2019-10-14 02:24:26 +00:00
|
|
|
|
class QTimer;
|
|
|
|
|
|
|
|
|
|
#ifdef quc
|
2020-12-24 10:00:09 +00:00
|
|
|
|
class Q_DECL_EXPORT SaveRunTime : public QObject
|
2019-10-14 02:24:26 +00:00
|
|
|
|
#else
|
|
|
|
|
class SaveRunTime : public QObject
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
static SaveRunTime *Instance();
|
|
|
|
|
explicit SaveRunTime(QObject *parent = 0);
|
2023-09-08 05:51:39 +00:00
|
|
|
|
~SaveRunTime();
|
2019-10-14 02:24:26 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static QScopedPointer<SaveRunTime> self;
|
|
|
|
|
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//日志文件路径
|
|
|
|
|
QString path;
|
|
|
|
|
//日志文件名称
|
|
|
|
|
QString name;
|
|
|
|
|
|
|
|
|
|
//最后的编号
|
2019-10-14 02:24:26 +00:00
|
|
|
|
int lastID;
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//保存间隔
|
2019-10-14 02:24:26 +00:00
|
|
|
|
int saveInterval;
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//开始时间
|
2019-10-14 02:24:26 +00:00
|
|
|
|
QDateTime startTime;
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//日志文件
|
2019-10-14 02:24:26 +00:00
|
|
|
|
QString logFile;
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//保存文件定时器
|
2019-10-14 02:24:26 +00:00
|
|
|
|
QTimer *timerSave;
|
|
|
|
|
|
|
|
|
|
private:
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//比较两个时间差值
|
2019-10-14 02:24:26 +00:00
|
|
|
|
void getDiffValue(const QDateTime &startTime, const QDateTime &endTime, int &day, int &hour, int &minute);
|
|
|
|
|
|
2021-10-07 02:57:25 +00:00
|
|
|
|
public Q_SLOTS:
|
|
|
|
|
//启动服务
|
|
|
|
|
void start();
|
|
|
|
|
//停止服务
|
|
|
|
|
void stop();
|
2019-10-14 02:24:26 +00:00
|
|
|
|
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//新建目录
|
|
|
|
|
void newPath();
|
|
|
|
|
//初始化日志文件
|
|
|
|
|
void initLog();
|
|
|
|
|
//追加一条记录到日志文件
|
|
|
|
|
void appendLog();
|
|
|
|
|
//保存运行时间到日志文件
|
|
|
|
|
void saveLog();
|
2019-10-14 02:24:26 +00:00
|
|
|
|
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//设置文件保存目录
|
2019-10-14 02:24:26 +00:00
|
|
|
|
void setPath(const QString &path);
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//设置文件名称
|
2019-10-14 02:24:26 +00:00
|
|
|
|
void setName(const QString &name);
|
2021-10-07 02:57:25 +00:00
|
|
|
|
//设置保存间隔
|
2019-10-14 02:24:26 +00:00
|
|
|
|
void setSaveInterval(int saveInterval);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SAVERUNTIME_H
|