Search code examples
qtqstringurldecodequrl

Reading percentage encoded url with umlauts with Qt


I am trying to read percentage encoded urls with umlauts, such as äüö,..., with Qt:

QString str = "Nu%CC%88rnberg"
qDebug() << QUrl::fromPercentEncoding(str.toUtf8());

But the output is Nu¨rnberg instead of Nürnberg. How can I correctly decode urls with umlauts in this form?

Regards,


Solution

  • I have done this issue but I am little confused with result. First if you want to use letter ü use %C3%BC not %CC%88 (according to https://www.w3schools.com/tags/ref_urlencode.asp). So you need

    QString str = "N%C3%BCrnberg";
    QString encoded = QUrl::fromPercentEncoding(str.toUtf8());
    

    But if you output it in qDebug() stream you can get different symbol (I guess it is because your default system encoding). But if you output it in GUI element you will have your ü symbol

    QMessageBox::information(this, "", encoded);
    

    this means main window.