Convert HTTP QUrl to file path on the server
Maybe someone know how I can get relative to specific folder file path from url for example
from
Quote:
"http://doc.qt.io/documents/readme.txt"
get only
Quote:
documents/readme.txt
without first slash "/"
from
Quote:
"/video/Qt/example.avi"
get only
Quote:
video/Qt/example.avi
without first slash "/"
I get several form of url from client applications but I need from that only file path without first "/" because then I can easily doing something like
How I can parse url for this format?
This statement
return file path but always with first slash "/", so then I need to remove it
It is a good solution? Or maybe QUrl have some better way?
Thanks,
Re: Convert HTTP QUrl to file path on the server
QString was not meant for a canonical url representation. It is a string class existing mostly due to the utf use cases.
What you are looking for is QUrl which was meant for use cases like this. Pass your path to that, and then get the "QFile-readable" path out of that, then pass it to QFile.
Re: Convert HTTP QUrl to file path on the server
This code solved my problem
Code:
qDebug
()<<
QDir("/").
relativeFilePath(path
);
Re: Convert HTTP QUrl to file path on the server
QString was not meant for a canonical url representation. It is a string class existing mostly due to the utf use cases. What you are looking for is QUrl which was meant for use cases like this. Pass your path to that, and then get the "QFile-readable" path out of that, then pass it to QFile.