PDA

View Full Version : trademark symbol?



gfunk
22nd February 2007, 00:33
I'm trying to print the trademark symbol - a superscript TM. But I'm not having any luck. I tried setting it to a font that supports it (like Tahoma and Arial), and put \x99 and \u2122 in a QString. But it just won't print it, all I get is a black rectangle character. Anyone ever have any luck with this?

jacek
22nd February 2007, 00:52
I tried setting it to a font that supports it (like Tahoma and Arial), and put \x99 and \u2122 in a QString. But it just won't print it, all I get is a black rectangle character.
I think that the problem is that you put that Unicode character in a non-unicode string. Do you set any codecs using QTextCodec::setCodecForCStrings() or QTextCodec::setCodecForLocale()?

Try:
QString msg( QString( "..." ) + QChar( 0x2122) );

gfunk
22nd February 2007, 01:09
Wow! That helped. Yeah, I was putting the character in a non-unicode string. Seems like I should rewrite this code using unicode strings where possible?
ie. use QString(L"blah") instead of QString("blah") ?

wysota
22nd February 2007, 01:15
If you want to display the string on a QLabel, you can use an sgml entity (i.e. the form &#xxx; )

camel
22nd February 2007, 09:35
Wow! That helped. Yeah, I was putting the character in a non-unicode string. Seems like I should rewrite this code using unicode strings where possible?
ie. use QString(L"blah") instead of QString("blah") ?

The cleanest thing is always to use QLatin1String or QString::fromUtf8() and friends.

This way you make sure that all conversions to unicode (which QString internally uses) are done in a sane way. (And not for example accidently depending on which locale your user has set up...)

If you want to make really sure that you have no implicit conversions, you can use the defines QT_NO_CAST_FROM_ASCII (http://doc.trolltech.com/4.2/qstring.html#QT_NO_CAST_FROM_ASCII) and QT_NO_CAST_TO_ASCII ("http://doc.trolltech.com/4.2/qstring.html#QT_NO_CAST_TO_ASCII). Note, that could imply a lot of tedious work to wrap everything though... ;-)