[Qt-interest] Have QXmlStreameWriter write the encoding information

Andreas Pakulat apaku at gmx.de
Wed Jun 3 12:36:06 CEST 2009


On 03.06.09 09:24:50, Marc Balmer wrote:
> Am 03.06.2009 um 09:06 schrieb Andreas Pakulat:
>>> What you want is a processing instruction line, so you should call
>>> writeProcessingInstruction(), i.e.
>>>    xml.writeProcessingInstruction("xml", "version=\"1.0\"
>>> encoding=\"UTF-8\"");
>>
>> That will produce
>>
>> <?xml version="1.0"?><?xml version="1.0" encoding="UTF-8"?>
>>
>> so definetly not what he wants.
>>
>> If you're writing into a QString there's simply no point in adding an
>> encoding, because the encoding is dictated by QString.
>
> actually yes, there is a point.  namely if you use the QString only  
> temporarely
> while composing the XML content and then later output it as ISO-8859-1
> using QString::toLatin1().  This does not work,

Then why are you creating a QString in the first place? Just use QByteArray
as output and the encoding will be there. 

> Imo, Qt does to much magic here.  But then I found a way to work around
> it, so my problem is definitely gone.

No, you're misusing QString for something its not meant for. QString is not
a byte container and hence has no encoding (except an internal one).

Andreas

-- 
Never reveal your best argument.



More information about the Qt-interest-old mailing list