Hi!
Ralph Glasstetter wrote:
> I just googled a bit and found a discussion like ours here, where they set
> the
> encoding of the output stream explicitely before writing a preferences
> file... please try this on your box to see if that works also with your Latin
> locale:
>
> stream.setEncoding(QTextStream::UnicodeUTF8);
> stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
> stream << doc.toString();
>
> in DVBcut at Line 258.
Oh well... there is the explanation for the double conversion. I should
have checked the docs for QTextStream, in particular the "<<" operator
with a QCString argument:
The string s is assumed to be Latin1 encoded independent of the
Encoding set for the QTextStream.
Who the f*ck told that operator to mess with the encoding?
Of course toCString() can't work correctly, then.
> You remember... toString() (as in rev69) did not work under Windows but with
> setting the encoding now it does! The behavoir under my UTF-8 Linux is
> unaffected and working as before in rev69 without the setEncoding()...
Sounds good.
> PS: setEncoding() together with toCstring() has the effect that it does no
> longer work under Windows... producing the same double converted filename as
> under Linux with rev70!
For toCString() to work correctly, the "<<" operator should write the
bytes unmodified (i.e. use QTextStream::Latin1 encoding). This should
also be the fastest mode (not that it would matter much).
Since we also use "<<" with a "const char*" argument, which has the same
properties, the cleanest solution is to do it this way:
stream.setEncoding(QTextStream::Latin1);
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
stream << doc.toCString();
If we ever replace the QTextStream with a std::ostream or another "byte
transparent" kind of stream, this variant will continue to work, while
the other one won't.
On my system, this creates a correctly encoded project file in both
Latin-15 and UTF-8 based locales. I'll check the Windows part this evening.
> PPS: In the above mentioned discussion someone wrote:
> 'This discussion so far can thus be summed up as "encodings are a pain in the
> ass and really hard to get right"'
Didn't I mention that already? ;-)
And the combination of encodings and Qt is a royal PITA.
--
Michael "Tired" Riepe <[EMAIL PROTECTED]>
X-Tired: Each morning I get up I die a little
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
DVBCUT-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dvbcut-user