【问题标题】:how can I create QUrl from encoded url如何从编码的 url 创建 QUrl
【发布时间】:2013-09-30 19:40:59
【问题描述】:

我有一个包含编码 URL 的 QString,这意味着您将其插入浏览器的 url,例如:

QString string = "http://domain.tld/index.php?some%20encoded&another%20encoded";

当我像创建 QUrl 时

QUrl(string);

它随机决定应该编码什么不应该编码,在这种情况下它会留下“?”和“&”解码,但再次编码百分比符号。所以目标 php 应用程序接收到“some%20encoded”而不是“some encoding”。

这似乎是 QT 在自动尝试解析“和修复”url 时的一些特性。这个功能可以通过调用来禁用

QUrl(string, QUrl::StrictMode);

在 qt 5+ 中完美运行,但在 qt 4 中,尽管它可以编译,但它的行为与我没有提供 StrictMode 参数一样。如何从我自己编码且不需要进一步编码的字符串创建 url?

【问题讨论】:

    标签: c++ qt


    【解决方案1】:

    你要找的是

    QUrl QUrl::fromEncoded (const QByteArray  &input ) [static]
    

    QUrl doc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 2011-12-25
      • 1970-01-01
      • 2015-01-07
      • 2014-07-17
      • 1970-01-01
      相关资源
      最近更新 更多