[Qt-interest] Does Qt support Unicode 5.1?

Constantin Makshin dinosaur-rus at users.sourceforge.net
Thu Mar 5 22:10:48 CET 2009


The problem is in your code. I opened Unicode.pdf in Adobe Reader and  
copied these characters into QLineEdit using clipboard. Everything was OK.

Please read  
http://en.wikipedia.org/wiki/UTF-16#Encoding_of_characters_outside_the_BMP  
to find the solution.

This code gives the correct result (look the attached file for the "full  
version"):

static QChar HighSurrogate (unsigned c)
{
     return QChar(((c - 0x10000) >> 10 & 0x3ff) + 0xd800);
}

static QChar LowSurrogate (unsigned c)
{
     return QChar((c & 0x3ff) + 0xdc00);
}

...

QChar testTiles[] = { HighSurrogate(0x1f000), LowSurrogate(0x1f000),  
HighSurrogate(0x1f001), LowSurrogate(0x1f001) };
QString testStr(testTiles, sizeof(testTiles) / sizeof(QChar));

To Qt developers: Your surrogate characters handling code seems to be  
wrong.

On Thu, 05 Mar 2009 21:27:51 +0300, Shaun Cummins <cumminss at gmail.com>  
wrote:
> I tried using some new characters introduced in Unicode 5.1 last night  
> but
> could not get the characters to print. My code was similar to the  
> following:
>
> QFontDabase fontData;
> int fontID = fontData.addApplicationFont(QString(":/MahjongFont.otf"));
> // added the font to a resource file in the application
> if (fontID != -1)
> {
>   QStringList fontNames = fontData.applicationFontFamilies(fontID); //
> just returned one name as expected
>   if (!fontNames.isEmpty())
>   {
> 	QString& fontName = fontNames.first();
> 	QFont mahjongFont = fontData.font(fontName,QString(),24);
> 	ui->testLine->setFont(mahjongFont); // testLine is a QLineEdit on this  
> form
> 	QChar testTiles = { 0x1f000, 0x1f001 };
> 	QString testStr(testTiles,2);
> 	ui->testLine->setText(testStr);
>   }
> }
>
> The above compiles and doesn't cause any runtime error. But the text
> displayed is just empty boxes. The font I used was downloaded from
> http://users.teilar.gr/~g1951d/download.html (downloaded the Unicode.otf
> file and renamed it to MahjongFont.otf)
>
> I tried using other characters and all of the ones in Unicode 5.0 worked
> fine and seemed to use the font I had downloaded (based on comparing the
> displayed text with the pdf that is also available at that download  
> page). I also noticed that the QChar class has an enumeration for when a
> character was introduced and only went up to Unicode 5.0.
>
> I was using the release version of Qt 4.5.0 on Windows Vista (Home  
> Premium).

-- 
Constantin "Dinosaur" Makshin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: application/octet-stream
Size: 949 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090306/5894cb73/attachment.obj 


More information about the Qt-interest-old mailing list