0

如何将此 IRI 转换为 URI?

http://down.qnwz.cn/uploads/media/broadcast/storymagazine/爱的底牌.mp3

我希望结果类型应该是 Qurl ,谢谢

看起来

QUrl QUrl::fromEncoded ( const QByteArray & input )

在这里不起作用。

>>> from PyQt4.QtCore import *
>>> url='http://down.qnwz.cn/uploads/media/broadcast/storymagazine/爱情的底牌.mp3'
>>> QUrl.fromEncoded (QUrl(url).toEncoded())
PyQt4.QtCore.QUrl('http://down.qnwz.cn/uploads/media/broadcast/storymagazine/爱情的底牌.mp3')
>>>
4

1 回答 1

0

我相信您想将非 latin1 字符转换为百分比编码。使用QUrl::toEncoded

 >>> QUrl(url).toEncoded()

PyQt4.QtCore.QByteArray(' http://down.qnwz.cn/uploads/media/broadcast/storymagazine/%C3%A7%C2%88%C2%B1%C3%A6%C2%83%C2%85% C3%A7%C2%9A%C2%84%C3%A5%C2%BA%C2%95%C3%A7%C2%89%C2%8C.mp3 ')

然后,您可以将其转换回 QUrl:

QUrl(QString.fromUtf8(QUrl(url).toEncoded()))
于 2013-06-14T06:43:25.690 回答