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

Ilya Kulakov kulakov.ilya at gmail.com
Thu Jan 22 19:23:39 GMT 2015


I'm using PyQt 5.4, Python 3.4.2

If I run interpreter in terminal, copy-paste that symbol and try to encode it to utf-8 it will finish without errors and print the same sequence of bytes I posted before.

Sent from my iPhone

> On 22 янв. 2015 г., at 23:30, Pavel Roskin <proski at gnu.org> wrote:
> 
> 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