如何将此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')
>>>
答案 0 :(得分: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()))