16,233
社区成员
发帖
与我相关
我的任务
分享
自己解决了。本身QT是4.8.7的。temp是utf8编码的中文网址。
//得到字节数组
QByteArray ba=temp.toLocal8Bit();
//排除了/:
QByteArray ba2 =ba.toPercentEncoding("/:");
//生成url
m_Url = QUrl::fromEncoded( ba2 );
不要用默认QURL或者setUrl(),会将百分号%解析成%25。于是服务器总是报错没有那个文件。
解决了吗?怎么解决?
QUrl original("http://example.com/?q=a%2B%3Db%26c");
QUrl copy(original);
copy.setQuery(copy.query(QUrl::FullyDecoded), QUrl::DecodedMode);
qDebug() << original.toString(); // prints: http://example.com/?q=a%2B%3Db%26c
qDebug() << copy.toString(); // prints: http://example.com/?q=a+=b&c