I want to get the Latin1 code for multiply sign ×
, but when I check the value inside the QChar
it has -41'×'
.
My code:
QString data = "×";
QChar m = data.at(0);
unsigned short ascii = (unsigned short)m.toLatin1();
When I debug, in the second line I see the QChar
value is -41'×'
.
I changed the code:
unsigned int ascii = c.unicode();
But I get the value 215 rather and I expect 158.
The multiply sign
×
is not an ascii sign, as you can see when checkingman ascii
if you are on a unix system.What its value is depends on the encoding, see here for its UTF representations. For example on UTF-8 it has the value
0xC397
which are two bytes. As is mentioned on the unicode page I linked 215 is the decimal value to represent this character in UTF-16 encoding, which is whatc.unicode()
returns. I don't know why you expect 158.There is an ascii multiply sign though, which is
*
.