Qml Image can not open file with bad symbols
-
Hi!
How can I open an image with symbols '%' or '&' etc?import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 Image { source: "file:////home/elnur/&'Test%25'.jpg" } }
Error:
qrc:/main.qml:20:5: QML Image: Cannot open: file:////home/elnur/&'Test%25'.jpg
-
Hi!
How can I open an image with symbols '%' or '&' etc?import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 Image { source: "file:////home/elnur/&'Test%25'.jpg" } }
Error:
qrc:/main.qml:20:5: QML Image: Cannot open: file:////home/elnur/&'Test%25'.jpg
@Elnur_Ismailzada
What is the actual name on disk of your//home/elnur/&'Test%25'.jpg
file? I'd be surprised if it actually has those characters in it...? -
@Elnur_Ismailzada
What is the actual name on disk of your//home/elnur/&'Test%25'.jpg
file? I'd be surprised if it actually has those characters in it...?@JonB this is the actual name of the file. User can enter any file name. It is test.
-
@JonB this is the actual name of the file. User can enter any file name. It is test.
@Elnur_Ismailzada said in Qml Image can not open file with bad symbols:
User can enter any file name. It is test.
User should enter a valid file name, depending on underlying OS... :-)
Anyway, I guess you should use URL encoding to avoid such situations, see url QML Basic Type
source: encodeURIComponent("/tmp/test#1.png")
-
@Elnur_Ismailzada said in Qml Image can not open file with bad symbols:
User can enter any file name. It is test.
User should enter a valid file name, depending on underlying OS... :-)
Anyway, I guess you should use URL encoding to avoid such situations, see url QML Basic Type
source: encodeURIComponent("/tmp/test#1.png")
@Pablo-J.-Rogina I tried encodeURIComponent. Error:
qrc:/main.qml:20:5: QML Image: Cannot open: file:////home/elnur/&'Тест%2525'.jpg
-
@Pablo-J.-Rogina I tried encodeURIComponent. Error:
qrc:/main.qml:20:5: QML Image: Cannot open: file:////home/elnur/&'Тест%2525'.jpg
@Elnur_Ismailzada could you please post your whole source code? I can see 4 / (slashes) which is suspicious
file:////home/elnur/...
-
@Elnur_Ismailzada could you please post your whole source code? I can see 4 / (slashes) which is suspicious
file:////home/elnur/...
@Pablo-J.-Rogina Thank you for your time and help. I made a mistake.
Answer:import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 Image { id: image Component.onCompleted: { source = "file://" + encodeURIComponent("/home/elnur/&'Test%25'.jpg") } } }