[Development] Why we *have to* remove codecFor... ?

Loaden loaden at gmail.com
Sun Apr 22 11:11:13 CEST 2012


Thanks for reply! I don't care the reason now, I just want know how to make
it work.
I am try UTF-8 of the source file, with or not with UTF-8 BOM, and try
fromLatin1/Utf8/Ascii too.
And all tried is failed!

In MSVC2010, If use some Chinese (CJK) strings, We have to save the source
file as UTF-8 with BOM format.
I am also try UNICODE (with or without BOM) too.
It's does't work too.

2012/4/22 Robin Burchell <robin+qt at viroteck.net>

> 2012/4/22 Loaden <loaden at gmail.com>:
> > Hi, All! I am only a physics teacher from China.  It makes me
> confused  that
> > I just noticed the codecFor... function is removed for now.
>
> It's removed primarily for sanity reasons. Not being able to reliably
> know what fromAscii/toAscii are actually going to do mean that they
> become pretty much unusable in library code (but there was never any
> warning, meaning it was a gigantic hard-to-debug trap) - and this is
> not even mentioning that they are called "fromAscii" and "toAscii",
> not "fromSomeMagicGlobalLocale" and "toSomeMagicGlobalLocale".
>
> Not having to worry about this means that there's a lot less chance of
> people shooting themselves in the foot, since prior to this, using
> those methods was almost never what you actually wanted when writing
> "portable" Qt code, and as a coincidence, should help performance a
> bit since codecs are no longer involved (plus the ASCII conversions
> are now inlined, from memory).
>
> > But please let's me know how to make this work with *MSVC2010*?
>
> Tell MSVC to save in unicode format, and use QString::fromUtf8 instead
> of QString::fromAscii. Some searching shows that this is possible
> fairly easily:
> http://stackoverflow.com/questions/5406172/utf-8-without-bom-in-visual-studio-2010
>
> There has also been talk about making QString's char* methods use to
> utf8 (meaning you'd be able to use QString foo("bunçh øf u†f8 here");
> and it'd work fine, but I never got around to writing that, I don't
> know if anyone else has started yet.
>



-- 
Best Regards
Yuchen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120422/feccd6c9/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 733 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120422/feccd6c9/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.qbp
Type: application/octet-stream
Size: 272 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120422/feccd6c9/attachment.obj>


More information about the Development mailing list