[PyQt] PyQt cannot trasform QString into str when reading emoji symbol from QClipboard

Pavel Roskin proski at gnu.org
Thu Jan 22 17:30:48 GMT 2015


That's a big mess. Surrogates should not be in unicode strings. It's
better to figure out how they got there. I guess it's something
specific to your Python or PyQt. I tried
QApplication.clipboard().text() with that symbol and it returns a
valid unicode character for me (Ubuntu 14.10, Python 3.4, PyQt
4.11.2).

You can use string.encode('utf-8', errors="surrogatepass") but it
won't combine surrogates - it would encode them individually. That's
if you just want to suppress the error.

You can use ord(string[n]) to read unicode character one by one and
then combine surrogates manually. Then you can make the correct
unicode string from the combined codes and that string would be
decodable.

Pavel


More information about the PyQt mailing list