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

Ilya Kulakov kulakov.ilya at gmail.com
Thu Jan 22 19:28:41 GMT 2015


Also returned str consists of 1 char instead of 4 (utf-8) or 2 (utf-16).

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