[Interest] Certain QTextCodecs causing crashes on Linux

Thiago Macieira thiago.macieira at intel.com
Wed Jul 31 22:39:16 CEST 2013


On quarta-feira, 31 de julho de 2013 19:39:28, Scott Aron Bloom wrote:
> QTextCodec * codec = QTextCodec::codecForName( "UTF-8" );
> QString a = codec->toUnicode( "a" );
> If ( a.isEmpty() )
>         // don't Show
> QChar aChar = tmp.at( 0 );
> If ( aChar.unicode() != 'a' )
>         // don't show
> 
> This look ok?

You want the fromUnicode operation. We know what the UTF-16 representation of 
U+0061 LATIN SMALL LETTER A is (one 16-bit word containing the value 0x61). We 
need to test how it's encoded in this codec.

	QChar letterA(0x61);
	if (codec->fromUnicode(&letterA, 1) != "a") // [1]
		// can't use

for all ASCII-compatible codecs, the result will be "a". In fact, that is true 
for all codecs that Qt 4 ships, except for UTF-16 and UTF-32.

In Qt 5, because we use ICU now, that's no longer true. It's also not true if 
someone else installs their own codecs.

[1] comparing to "a" is a trick that works only if your execution charset is 
also ASCII-compatible. In 20 years doing software development, I have yet to 
see an environment that isn't. The ability to have different source, 
translation and execution charsets is a legacy in C and C++ from the olden 
days.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130731/ccf74aec/attachment.sig>


More information about the Interest mailing list