PDA

View Full Version : QFile - file read parts of the buffer



eugen_Qt
7th November 2009, 22:43
:)

All greetings! I would be very grateful if someone show you in my question ...

I am writing a program backup file, it already works, but only with small files.

To work with large files, you must read fail parts, but not completely, that would not take much memory...



...
QFile fileRead(filename);

const int pageSize = getpagesize();
const int fileSize = fileRead.size();

int parts = fileSize/pageSize;
if (fileSize%pageSize != 0)
parts++;

buffer = new char[pageSize];

for (int partsCount = 0; partsCount < parts; partsCount++) {
//fileRead.read(buffer, fileSize); // ???
...

RSX
7th November 2009, 23:14
How about this?

QByteArray b;
while (!fileRead.atEnd()) {
b += f.readLine();
}

eugen_Qt
7th November 2009, 23:32
Thanks! that responded...)

this will work - provided that the string will not be too long ... and if the string is too long?
or the turnover is too short - the buffer will be a little?

in any case be restricted with the size of buffer, in this case a buffer size equal to the page (since downloading a file produced by paging)...

function "getpagesize ()" returns the page size ...

ie how to read the back fail bytes - for example from the middle of the file?

RSX
8th November 2009, 12:26
If you want to read the file from the middle then:

QFile f("f.txt");
QByteArray b;
if (f.open(QFile::ReadOnly)) {
f.seek(f.size() / 2);
while (!f.atEnd()) {
b += f.readLine();
}
f.close();
}

eugen_Qt
10th November 2009, 15:52
Thank you very much for the tip!!!