Solved How to use QImage to load a file with name "#.png"?
-
There is a file named "#.png" in my D disk
When I use the following qml code
Image {
source: "file:///D:/#.png"
}
and I directly get an error "QML Image: Cannot open: file:///D://#.png"
but everything is fine if I rename the file name to "1.png", how to solve this problem -
I think the format of file path is incorrect .
For Example,try the following:
D:/#.pngFor more information , follow - link
-
if the path format is incorrect, rename to 1.png should be the same result.
-
@NixUhs said in How to use QImage to load a file with name "#.png"?:
There is a file named "#.png" in my D disk
When I use the following qml code
Image {
source: "file:///D:/#.png"
}
and I directly get an error "QML Image: Cannot open: file:///D://#.png"
but everything is fine if I rename the file name to "1.png", how to solve this problemYou have to escape hash-tag symbol with
\
(cf https://bugreports.qt.io/browse/QTBUG-68635)
Following should work:Image { source: "file:///D:/\#.png" }
-
Or use
encoreURIComponent
like mentionned at the end of theurl
documentation. -
@GrecKo said in How to use QImage to load a file with name "#.png"?:
encoreURIComponent
encodeURIComponent
-
Solved, I use "replace(QChar('#'), "%23")" to every path QString
source: "file:///D:/#.png" not working
encodeURIComponent not working