-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathworker.cpp
45 lines (40 loc) · 1.1 KB
/
worker.cpp
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
#include "worker.h"
#include <QTextStream>
#include <QDebug>
Worker::Worker(QObject *parent) : QObject(parent){
giFileSize = 0;
}
void Worker::worker_slot_loadFile(QFile *file)
{
QString line = "";
QString text = "";
QTextStream in(file);
while (!in.atEnd()) {
line = in.readLine();
text.append(line + "\n");
}
in.flush();
file->close();
text.remove(text.lastIndexOf("\n"),1);
emit worker_signal_appendText(text);
}
void Worker::worker_slot_tailFile(QFile *file)
{
if(file->size() > giFileSize) {
int liDiff = file->size() - giFileSize;
if(file->open(QIODevice::ReadOnly | QIODevice::Text)) {
if(file->seek(giFileSize)) {
QString lsText = QString(file->read(liDiff));
emit worker_signal_insertText(lsText);
giFileSize = file->size();
}
file->close();
}
} else {
giFileSize = file->size();
}
}
void Worker::worker_slot_setCurrentFileSize(int aiFileSize)
{
this->giFileSize = aiFileSize;
}