The working solution, for the moment (i.e., as opposed to writing the data as it arrives), involves appending the fully downloaded data to the output file a little at a time:
bool DownloadManager
::saveToDisk(const QString &fileName,
QIODevice *inputDevice
) { if (ok) {
const qint64 MAX_LEN = 1024; // arbitrary...sort of
while (ok && !inputDevice->atEnd())
ok = file.write(inputDevice->read(MAX_LEN)) != -1;
file.close();
}
return ok;
}
bool DownloadManager::saveToDisk(const QString &fileName, QIODevice *inputDevice) {
QFile file(fileName);
bool ok = file.open(QIODevice::Append);
if (ok) {
const qint64 MAX_LEN = 1024; // arbitrary...sort of
while (ok && !inputDevice->atEnd())
ok = file.write(inputDevice->read(MAX_LEN)) != -1;
file.close();
}
return ok;
}
To copy to clipboard, switch view to plain text mode
Clearly the original problem was related to the file size, which at first glance doesn't seem to have much to do with threading. I'm frankly a bit annoyed at Qt, or Android, or both! :P
Bookmarks