gpt4 book ai didi

c++ - QML 图像不加载图像源中具有非 ASCII 字符的图像

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:04:30 24 4
gpt4 key购买 nike

我必须在基于 Linux 的设备上显示来自 USB 设备的图像。我的 USB 有一个非 ASCII 字符的文件夹。它被替换为“?”性格。

原始路径:"file:///tmp/USB6/§§§§/Koala.jpg"

QML 返回错误:"QML Image: Cannot open: file:///tmp/USB6/?????/Koala.jpg"

如何使用此路径加载我的图像?

Image {
id: mainImage
source: iconRole
asynchronous: true
sourceSize.width: screenSize_Width
sourceSize.height: screenSize_Height
fillMode: Image.PreserveAspectCrop
onSourceChanged: {
console.log("SOURCE = ",source)
}
}
  1. 我得到的日志:SOURCE = file:///tmp/USB6/§§§§/Koala.jpg
  2. 我获取 QML 图像时出错:无法打开:file:///tmp/USB6/?????/Koala.jpg

最佳答案

关于 URL 的 Qt 文档:

Additionally, URLs may contain encoded characters using the'percent-encoding' scheme specified by RFC 3986. These characters willbe preserved within properties of type url, to allow QML code toconstruct precise URL values. An exception to this rule is thepreemptive decoding of directory-separator characters ('/') - thesecharacters are decoded to allow the URL to be correctly classified.

For example, a local file containing a '#' character, which wouldnormally be interpreted as the beginning of the URL 'fragment'element, can be accessed by encoding the characters of the file name:

Image { source: encodeURIComponent("/tmp/test#1.png") }

This basic type is provided by the QML language.

关于c++ - QML 图像不加载图像源中具有非 ASCII 字符的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49854353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com