1

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.

Drise
  • 4,310
  • 5
  • 41
  • 66
ilya
  • 1,103
  • 14
  • 36

1 Answers1

2

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);
rocambille
  • 15,398
  • 12
  • 50
  • 68
  • Your sample works fine, but when I use another url with Russian characters "http://привет.рф", then pretty printing fails (still shows Punycode). When I use "http://привет.com", then it's ok. Tested on Qt 5.6.2. – ilya Nov 18 '16 at 14:33