Hello,
I have recently used the QXmlStreamWriter class to generate my xml trees. In Qt documentation, it is explained that QXmlStreamWriter uses UTF-8 by default.
However, if I open the resulting file in a hex editor, it looks like the xml is in UTF-16 instead.
In the hex editor, I have the following caracters:
FF FE 3C 00 3F 00 78 00 6D 00 6C 00 <?xml
FF FE 3C 00 3F 00 78 00 6D 00 6C 00 <?xml
To copy to clipboard, switch view to plain text mode
I noticed "FF FE" as the UTF-16 BOM as well as the file size which is twice the number of characters.
I changed my code in order to force the UTF-8 as follow:
return;
QXmlStreamWriter xml(&fout);
xml.setCodec("UTF-8");
if( m_chain->serialize(&xml) ) {
...
}
QFile fout(m_filename);
if( !fout.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text) )
return;
QXmlStreamWriter xml(&fout);
xml.setCodec("UTF-8");
if( m_chain->serialize(&xml) ) {
...
}
To copy to clipboard, switch view to plain text mode
But when I open the xml file in the hex editor, I still have the same result. 
Is there something I forgot to set up ?
Thanks for your advices.
Z.
Bookmarks