QFile - file read parts of the buffer
:)
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...
Code:
...
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); // ???
...
Re: QFile - file read parts of the buffer
How about this?
Code:
while (!fileRead.atEnd()) {
b += f.readLine();
}
Re: QFile - file read parts of the buffer
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?
Re: QFile - file read parts of the buffer
If you want to read the file from the middle then:
Code:
if (f.
open(QFile::ReadOnly)) { f.seek(f.size() / 2);
while (!f.atEnd()) {
b += f.readLine();
}
f.close();
}
Re: QFile - file read parts of the buffer
Thank you very much for the tip!!!