c++qtqt5punycodequrl

QString from Punycode QUrl


If I put url http://www.äsdf.de/bla/bla into QUrl, how can I then restore url with original symbols?

It's ok that QUrl will fix some characters, but I'd like to display original äsdf in url instead of xn--sdf-pla.

I am aware about QString QUrl::fromAce(const QByteArray &domain), but it requires QByteArray instead of QUrl instance.


Solution

  • You can use QUrl::toDisplayString with the default PrettyDecoded formatting option, or any other value among 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);