Right, so your code has several flaws as follows:
It is using hard coded windows paths. This could be appropriate for debugging or an example, but probably not for the final code.
It does not check whether the operations succeed.
It does not print the error strings when the operations fail.
You only read 512 bytes maximum.
You are doing a simple copy when QFile::copy() could do the same.
You do not need to close these descriptors explicitly since it is RAII you work with, not low-level C, luckily.
You may be having the filesystem mounted, and Windows might impose some limitation in that regard. Make sure that filesystems on the physical drive ("D: in your case?") are not mounted if you happen to read from physical drive as opposed to a binary image.
This is the code what I would write if I were you:
// "input.bin" can be replaced with any binary or physical drive
// you wish to back up about your physical drive.
QFile dsk("input.bin");
if (!dsk.open(QIODevice::ReadOnly))
qDebug() << "Failed to open:" << dsk.errorString();
QFile img("output.bin");
if (!img.open(QIODevice::WriteOnly))
qDebug() << "Failed to open:" << img.errorString();
QFileInfo fileInfo(dsk.fileName());
qint64 size = fileInfo.size();
for (qint64 bytes = 0; bytes < size, bytes+=data.size()) {
readBytes = myInputFile.read(chunkSize);
if (readBytes.isEmpty()) {
qDebug() << "no data was currently available for reading, or that an error occurred, error string:" << dsk.errorString();
} else {
if (img.write(readBytes) != readBytes.size())
qDebug() << "Failed to write all:" << img.errorString();
}
}
Theoretically, you could even add this loop if you cannot unmount, provided you are only interested in the file contents itself, but then you are going towards compression:
QDirIterator it("D:/", QDirIterator::Subdirectories);
while (it.hasNext()) {
// backup each file: it.next()
}
This is probably not what you may want here though, so just mentioning it for completeness.