Qml中Image加载图片再不同平台的方式

今天用QML中Image加载win系统下的本地路径图片的时候,

发现无论加绝对路径或file://+path都打不开,就很奇怪,经过一番

查阅发现,各个系统的加载方式都不相同,

win系统:

Image {
      id:  previewImage
      anchors.fill: parent
      source: "file:///"+"C:/Desert.jpg"
      fillMode: Image.PreserveAspectCrop
}

绝对路径前面要加 "file:///" 三个下划线,否则加载不出来

linux系统和安卓系统:

这两个系统是一样的路径:“file://”+path

 Image {
            id:  previewImage
            anchors.fill: parent
            source: "file://" +"/storage/emulated/0/Tencent/QQfile_recv/AAAEDED.png"
            fillMode: Image.PreserveAspectCrop
        }

绝对路径前面要加"file://"两个下划线,否则会报错加载不出来

资源环境加载:

再QML中加载资源环境和qtC++中加载不一样,不用加前缀:qrc://


你可能感兴趣的:(QML)