PDA

View Full Version : QtUrl Problem with Windows 7 - 64 bit



vsthakur1
13th November 2012, 02:41
Our application is a 32 bit application . When it is installed in windows 7 64bit, typically it install at
“C:\Program Files (x86)” location, instead of ““C:\Program Files”. We are constructing a Url based on the install location and and pass it around as a part of web service.The way , we are constructing the Url is like this –
ppmPath = “http://” + ipAddress + “:13007/” + folder + “.ppm” + “?filePath=” + applicationDirPath + “/” + FIRMWARE;
QUrl ppmURL( ppmPath, QUrl::TolerantMode ); ppmPath = QString( ppmURL.toEncoded() );

The variable types and meaning are usual.
Since “applicationDirPath” for Windows 7 64 bit contains one closing bracket “)” -for “(x86) substring – apparently the URL is broken. If we install it to any other location, it works perfectly, even though the
location has any other special character.
How to deal with “)” character in the URL , so that is is not broken ?

amleto
13th November 2012, 20:45
(=%281
)=%29

e.g.

http://www.google.co.uk/search?q=%281hello%29

ChrisW67
14th November 2012, 22:50
How to deal with “)” character in the URL , so that is is not broken ?
Use QUrl to build the URL in the first place (rather than pasting strings together). You'll find it does the encoding work for you.

You will also find the open and close parentheses are perfectly legal characters in the query portion of a URL, but spaces are not.
http://tools.ietf.org/html/rfc3986 (Section 3.4, 3.3, and 2.2)



QUrl url;
url.setScheme("http:");
url.setHost(ipAddress);
url.setPort(13007);
url.setPath(QString("%1.ppm").arg(folder));
url.addQueryItem("filepath", QString("%1/FIRMWARE").arg(applicationDirPath));
qDebug() << url.toEncoded();
// "http:://127.0.0.1:13007/some%20folder.ppm?filepath=C:/Program%20Files(x86)/SomeApplication/FIRMWARE"


Different systems are tolerant of badly formed URLs to different degrees, and incorrectly handle valid URLs also. If you are faced with a broken consumer of the URL then you can do this:


url.addEncodedQueryItem(
QUrl::toPercentEncoding("filepath"),
QUrl::toPercentEncoding(QString("%1/FIRMWARE").arg(applicationDirPath))
);
qDebug() << url.toEncoded();
// "http:://127.0.0.1:13007/some%20folder.ppm?filepath=C%3A%2FProgram%20Files% 28x86%29%2FSomeApplication%2FFIRMWARE"

to be extra sure.