[PyKDE] QByteArray and unicode
Jim Bublitz
jbublitz at nwinternet.com
Sat Dec 24 08:40:18 GMT 2005
On Friday 23 December 2005 11:11, Orcan Ogetbil wrote:
> Hi,
> using the following code, I can get the track title that's being played in
> amarok.
>
> [code]
> import dcop
>
> dcopclient = dcop.DCOPClient()
> dcopclient.registerAs("amarokapp")
> dcopclient.rc = dcop.DCOPRef("amarok", "player")
>
> result = dcopclient.rc.call("title()")
> title = result.data.data()
>
> print title
> [/code]
>
> The problem is, when the track title contains non-ascii characters, they
> are not displayed properly.
>
> The 'result' is a QByteArray object,
> 'result.data.data()' is a ascii python string
>
> How and where should I set the encoding to display the track title
> properly? (and how do I convert the QByteArray object to a unicode QString
> object?)
Take a look at PyKDE/doc/dcopext.html or examples/example_dcopext.py. PyKDE
doesn't support the method you're using (but see below), because there's no
easy way to convert the QByteArray to the appropriate object type using
Python.
title () should return a QString, and using the method outlined in the docs
will get you a QString from title (). The code that does it is in
extensions/dcopext.py and uses the dcop_add and dcop_next methods coded in
C++ and compiled as part of sip/kdecore/bytearray.sip - you could use those
methods in your own code if you want to duplicate the Python code in
dcopext.py.
Jim
More information about the PyQt
mailing list