简体   繁体   中英

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

<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

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

The image is recognized and displayed fine within the QT Creator's GUI einvoronment. BUT, when deployed to android there's a runtime error from.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?

Also, if QT attempts to introduce a multi-platform resource-abstraction layer over each platform; how does it handle various resolutions? For instance, in Android there's typically a separate folder for each DPI range. Does it do any kind of automatic scaling / conversions? (obviously not but then how to provide these various bitmaps to QT). It's related.

These issues is related URL on device's environment. So you should link URL on the code. Try like the below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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