简体   繁体   English

使用 QML (QT) 在 Android 上无法加载来自资源的图像

[英]Image from resources won't load on Android using QML (QT)

Seems like basic stuff:看起来像基本的东西:

1) there's an image defined within an RCC file 1) 在 RCC 文件中定义了一个图像

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
        <file alias="image.png">images/image.png</file>
    </qresource>
</RCC>

2) the image is referenced within a QML file 2) 图像在 QML 文件中被引用

Image {
            source:  "images/image.png"
        }

The image is recognized and displayed fine within the QT Creator's GUI einvoronment.该图像在 QT Creator 的 GUI 环境中可以很好地识别和显示。 BUT, when deployed to android there's a runtime error from.SO但是,当部署到 android 时,出现运行时错误。SO

armeabi-v7a.so: qrc:/main.qml:76:9: QML Image: Cannot open: qrc:/images/image.png

Now considering I wanted to do this the 'proper' way ie rely on QT's multi-platform capabilities and resource management and do not do any hacky stuff by tinkering with android folder, what is the proper way?现在考虑到我想以“正确”的方式做到这一点,即依靠 QT 的多平台功能和资源管理,并且不要通过修补 android 文件夹来做任何骇人听闻的事情,正确的方法是什么?

Also, if QT attempts to introduce a multi-platform resource-abstraction layer over each platform;此外,如果 QT 试图在每个平台上引入多平台资源抽象层; how does it handle various resolutions?它如何处理各种分辨率? For instance, in Android there's typically a separate folder for each DPI range.例如,在 Android 中,每个 DPI 范围通常都有一个单独的文件夹。 Does it do any kind of automatic scaling / conversions?它是否进行任何类型的自动缩放/转换? (obviously not but then how to provide these various bitmaps to QT). (显然不是,但是如何将这些不同的位图提供给 QT)。 It's related.这是相关的。

These issues is related URL on device's environment.这些问题与设备环境中的 URL 相关。 So you should link URL on the code.所以你应该在代码上链接 URL 。 Try like the below:尝试如下:

Image { source:  "qrc:/images/image.png"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM