Getting invalid path from file dialog
-
Hey, I'm on windows and paths I get from qml file dialogs are in the format "File:///C/User/..." (notice the 3 /). When converting it to a
QUrl
and then callingpath()
on it, it gives me an invalid path like "/C/User/...", does anyone have an idea how to correct approach to do this would be? -
@Creaperdown
Start by testing with literals what will work. I expectedfile:///C:/Users/...
to work. You have now introducedfile://C:/Users/...
. -
@Creaperdown
Are you wanting a local file path from the Url? What doesQUrl::toLocalFile()
return?The 3
/
s are expected. But I thought there would be an extra:
for the drive:file:///C:/User/...
. -
@Creaperdown
I think you will find thatQUrl::path()
returns a Url path (probably with schema removed), not a (local) file path which you seemed to expect it to do?localPath()
converts from Url to file path. -
@JonB I don't get it. I have a string like
file://C:/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.pdf
and I simply want the actual path to it, with no scheme.
toLocalFile
is gicing me//c/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.PDF 1.5
for some reason andpath()
gives me/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.PDF 1.5
.What can I do to just get the path to my file:
C:/Users/...
? -
@Creaperdown said in Getting invalid path from file dialog:
I don't get it. I have a string like
file://C:/Users/prtnp/Librum/build/librum_localLibraries/13824929713553088125/ac17af33-67b7-4b57-a6eb-e7bb69cc0d3f.pdf
Can you please start being consistent in what you report, since it is critical. You begin by telling us
format "File:///C/User/..." (notice the 3 /).
. Now you show it with 2//
s. You also saidtoLocalFile() seems to return the correct thing
. Now you say it does not. -
@Creaperdown
Start by testing with literals what will work. I expectedfile:///C:/Users/...
to work. You have now introducedfile://C:/Users/...
. -
@JonB Thank you. I have gone over it again, realized that all the paths I get from Qml are in the format "file:///" and that it only accepts paths with in the format "file:///", then I have found that
toLocalPath
seems to convert it to what I want and I changed it accordingly -
-
@Creaperdown
I don't use QML, but if file dialog returns Urls of formfile://
but it needs to befile:///
that would be strange/unhelpful. But I don't know. -
@JonB It would be a bug since the schema is
file://
(two/
) and the path is/foo/bar
. And since the path must always start with a/
it'sfile:///C:/foo/bar
- everything else is wrong.