QString::fromUtf8 problems converting micro sign
I am trying to convert the unicode micro-sign to use in a QString. I have tried the following:
But the string isn't the micro-sign but a question mark in a circle.
I also tried:
With the same result.
When using this with PyQt:
Code:
s
= QString.
fromUtf8(b.
data(), b.
length())
or
both c and b when I print them are also the question mark in the circle. When I try to convert to a QString I get the following error from the python interpreter:
Code:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in position 0:ordinal not in range(128)
I have tried a variety of combinations and googled everywhere for an adequate solution, to no avail.
FWIW, the python string conversion works as I'd expect, but I need a QString:
Code:
>> s = unichr(181).encode("utf8")
>> print s
>> µ
Traceback (most recent call last):
File "<input>", line 2, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Any help with this is greatly appreciated.
Re: QString::fromUtf8 problems converting micro sign
0xb5 is very unlikely to be a micro. The best thing you can do is to just put the real micro character in the file and save it with utf-8 encoding. Also make sure your font contains a micro character at this position.
Re: QString::fromUtf8 problems converting micro sign
The Unicode code point for the "Micro sign" is \u00b5. In UTF-8 encoding this is a two byte sequence \xc2\xb5. You could also use Greek small letter mu \u03bc.
Any of these:
This works for me but I am not sure if it is by-design or by-accident:
Look up Unicode code points here: http://www.unicode.org/charts
Convert into a bucket of other forms here: http://people.w3.org/rishida/tools/conversion/
Re: QString::fromUtf8 problems converting micro sign
Thanks! This is a big help.