[Development] Why we *have to* remove codecFor... ?
robin+qt at viroteck.net
Sun Apr 22 10:25:56 CEST 2012
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.
More information about the Development