-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwritethread.cpp
More file actions
32 lines (28 loc) · 864 Bytes
/
writethread.cpp
File metadata and controls
32 lines (28 loc) · 864 Bytes
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
#include "writethread.h"
#include "QString"
#include "QFile"
#include "QDebug"
#include "QSaveFile"
WriteThread::WriteThread(QString fileName, QByteArray data)
{
// by this point, the data is corrupt.
//so in short, before we pass it to the write threads constructor, everything is good, once there, its messed up
qDebug() << fileName;
qDebug() << "Data: " << *data;
this->fileName = fileName;
this->data = data + '\0';
}
void WriteThread::run() {
qDebug() << "WriteThread: " << data;
bool result = write ();
if(result) qDebug() << "Successfully written";
else qDebug() << "Error, write failed";
}
bool WriteThread::write() {
QSaveFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return false;
if (-1 == file.write(data))
return false;
return file.commit();
}