Convert QUrl with percent encoding into string

后端 未结 3 646
轻奢々
轻奢々 2021-01-02 15:05

I use a URL entered by the user as text to initialize a QUrl object. Later I want to convert the QUrl back into a string for displaying it and to check it using regular expr

3条回答
  •  無奈伤痛
    2021-01-02 15:40

    I am not sure why toDisplayString(QUrl::FullyDecoded) does not work.

    After trying several versions I have found that copy.query(QUrl::FullyDecoded) does decode the query part. The Documentation has an example with the the following code does return the decoded URL:

    QUrl url("http://test.com/query?q=%2B%2Be%3Axyz%2Fen");
    url.setQuery(url.query(QUrl::FullyDecoded), QUrl::DecodedMode);
    qDebug() << url.toString();
    

    To solve the problem this way is not optimal because the query part is copied without need.

提交回复
热议问题