PDA

View Full Version : Writing raw bytes as text?



DiamonDogX
18th May 2009, 16:19
I have a file that I wrote bytes to (MyFile below)... these bytes were actually just xml text originally, but were written as bytes or a bytearray. My question is how would I take those raw bytes and write them as the xml text they represent to a different file?


QFile fileReadIn ("MyFile");
if (fileReadIn.open( QFile::ReadOnly ))
{
QFile testFile( "Result.xml" );
testFile.open( QIODevice::WriteOnly );
testFile.write(fileReadIn.readAll());
}

caduel
18th May 2009, 17:56
That depends on the contents of your input file.
Could you please clarify what you mean by "written as bytes or a bytearray"?

Basically: You need to read them "inverse to the way you wrote them", convert that bytearray into a QString and then write that (in the desired encoding) to your output file.