I create a URL query like this:
QString normalize(QString text)    
{    
    text.replace("%", "%25");    
    text.replace("@", "%40");    
    text.replace("‘", "%27");    
    text.replace("&", "%26");    
    text.replace("“", "%22");    
    text.replace("’", "%27");    
    text.replace(",", "%2C");    
    text.replace(" ", "%20");    
    return text;    
}    
QString key = "usermail";
QString value = "[email protected]";    
QUrlQuery qurlqr;    
qurlqr.addQueryItem(normalize(key), normalize(value));
QString result = qurlqr.toString();
The result that's be expecting is :
usermail=aemail%40gmail.com. 
But I received:
[email protected]
I don't know why. Can you help me?
(I'm using Qt5 on Win7)
QUrlQuery's toString by default decodes the percent encoding. If you want the encoded version try:
qurlqr.toString(QUrl::FullyEncoded)
Also you don't need to manually encode the string by replacing characters; you could instead use QUrl::toEncoded() (I suggest you read the QUrlQuery documentation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With