20

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.

Daenyth
  • 35,856
  • 13
  • 85
  • 124
Gad D Lord
  • 6,620
  • 12
  • 60
  • 106

2 Answers2

34

Use QUrl::toPercentEncoding (static method ;))

Daenyth
  • 35,856
  • 13
  • 85
  • 124
pronebird
  • 12,068
  • 5
  • 54
  • 82
3

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

user
  • 23,260
  • 9
  • 113
  • 101