-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventlog.cpp
More file actions
49 lines (43 loc) · 1.03 KB
/
eventlog.cpp
File metadata and controls
49 lines (43 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "eventlog.h"
#include <QTextStream>
#include <QDebug>
EventLog::EventLog(const QString & logname)
{
logFile = new QFile(logname);
}
EventLog::~EventLog()
{
delete logFile;
}
void EventLog::ReadLog()
{
logFile->open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(logFile);
QString line = in.readLine();
int indexSpace;
while (!line.isNull()) {
indexSpace = line.indexOf(" ");
QString date = line.left(indexSpace);
QString event = line.right(line.length()-indexSpace-1);
Dates.append(date);
Events.append(event);
line = in.readLine();
}
foreach (QString event, Events) {
if(EventList.indexOf(event)<0)
{
EventList.append(event);
}
}
logFile->close();
}
void EventLog::WriteLog()
{
if (!logFile->open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(logFile);
for (int i=0;i<Dates.length();i++) {
out <<Dates[i]<<" "<<Events[i]<< "\n";
}
logFile->close();
}