QString from Punycode QUrl

QString from Punycode QUrl

本文关键字:QUrl Punycode from QString      更新时间:2023-10-16

如果我将url http://www.äsdf.de/bla/bla放入QUrl,我如何才能恢复url与原始符号?

QUrl将修复一些字符,但我想在url中显示原始äsdf而不是xn--sdf-pla

我知道QString QUrl::fromAce(const QByteArray &domain),但它需要QByteArray而不是QUrl实例。

您可以将QUrl::toDisplayString与默认的PrettyDecoded格式选项一起使用,或者在enum ComponentFormattingOption中使用任何其他值:

QUrl url{"http://www.äsdf.de/bla/bla"};
QString original_string =
    url.toDisplayString(); // default is QUrl::PrettyDecoded
QString original_string_with_encoded_spaces =
    url.toDisplayString(QUrl::EncodeSpaces);