You certainly do not want to open the file with the QIODevice::Text flag: it will mangle carriage returns and line feeds in your binary data on Windows.
Why bother with all the copying and leaking memory? You have a pointer to the data and a data length... QIODevice::write() has a variant to fit. The whole function comes down to:
void write_bin_file
(unsigned long datasize,
unsigned char *dataPtr,
QString directory
) {
QFile DummyFile
(directory
);
qint64 bytesWritten = DummyFile.write(reinterpret_cast<const char*>(dataPtr), datasize);
if (bytesWritten < datasize) {
// error
}
DummyFile.close();
}
}
void write_bin_file(unsigned long datasize, unsigned char *dataPtr, QString directory)
{
QFile DummyFile(directory);
if(DummyFile.open(QIODevice::WriteOnly)) {
qint64 bytesWritten = DummyFile.write(reinterpret_cast<const char*>(dataPtr), datasize);
if (bytesWritten < datasize) {
// error
}
DummyFile.close();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks