QFile doesn't recognize file:/// url path format

Dean Chen picture Dean Chen · Jan 7, 2014 · Viewed 18.1k times · Source

I get the file path from Qml like this:

mainView.projectFilePath = Qt.resolvedUrl(newProjectFileDlg.fileUrl).toString();

The above file path looks like this: file:///C:/uuuu.a3

But when this path is passed to QFile, it complains

The filename, directory name, or volume label syntax is incorrect

How to solve this problem?

Answer

claudiub picture claudiub · Feb 17, 2014
QUrl url(newProjectFileDlg.fileUrl);
url.toLocalFile();

This is probably what you need. It will return "C:/uuuu.a3" in your case.