How to encode URL parameters in QT?

18,947

Solution 1

Use QUrl::toPercentEncoding (static method ;))

Solution 2

In QML you can use encodeURIComponent(str), it's a standard JS function that is supported by QML.

Share:
18,947

Related videos on Youtube

Gad D Lord
Author by

Gad D Lord

I am a software developer coding in: Dart, Flutter, JavaScript, Delphi, PowerShell, C#, Python. I run a microISV company mtg.studio Ltd. which is focused on Magic: the Gathering card game tools. https://www.mtgstudio.com http://www.makedeck.com

Updated on April 09, 2020

Comments

  • Gad D Lord
    Gad D Lord over 2 years

    I have the following URL

    QString url = "http://www.gigacooldomainname.com/" + setName + "/" + fileName + ".jpg"
    

    where setName and fileName are QString variables.

    I wish to have the following:

    QString url = "http://www.gigacooldomainname.com/" + QUrlParameter::encode(setName) + "/" + QUrlParameter::encode(fileName) + ".jpg"
    

    Unfortunately there is not such QUrlParameter class or encode method.

    I know I can write one by myself but was curious if there is already an existing solution in QT4.

    I am also not interested in Q3Url::encode solution since I don't have the Q3Url headers.

  • Nulik
    Nulik about 4 years
    and how do you do this in QML ?
  • user
    user about 3 years
    @Nulik, encodeURIComponent(). Posted as an answer below.