I think i am having a fundamental misunderstanding of how all of this works, I am trying to combine 2 hexfiles in my QDataStream and then output them to a new QFile.
QFile filea( file1 );
QFile fileb( file2 );
QByteArray ba;
QDataStream ds(ba);
ds << filea.readAll();
ds << fileb.readAll();
QFile result("C:/Users/Aaron/Desktop/mergedfile.txt");
result.open(QIODevice::ReadWrite);
result.write(ba);
The result is just an empty file, any suggestions?
You have the following errors:
If you are only going to read a file, you must open it with the ReadOnly mode, if you are going to write it you must use WriteOnly, in your case you do not have it with filea, fileb and result.
The QByteArray you are using it to read the data of the filea and fileb files, and then write it to result, so it must be read and write. You are using the following QDataStream constructor:
And since the QByteArray is read only because it is not the appropriate constructor, you must use the other constructor:
Using the above we obtain the following: