Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Show image from assets in QML
Forum Update on Monday, May 27th 2025

Show image from assets in QML

Scheduled Pinned Locked Moved Mobile and Embedded
androidassetsimageqml
3 Posts 2 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    m_andrej
    wrote on last edited by m_andrej
    #1

    Hi,
    I'm bundling a lot of *.jpg images in my application as Android assets, as described in http://doc.qt.io/qt-5/platform-notes-android.html
    How can I show the images in QML Image element? The above page states that I should be able to access them by prefixing the file with assets:/. This works in C++, but not in QML.
    I tried code like this in various variants:

    Image {
    	anchors.fill: parent
    	source: "file://assets:/be_01.jpg"
    	fillMode: Image.PreserveAspectCrop
    	asynchronous: true
    }
    

    Unfortunately I can't use resource system for the images because they have around 100 MB in size.

    EDIT: I also tried to add this C++ code to find out absolute path of the file:

    QFile dbFile("assets:/be_01.jpg");
    qDebug() << dbFile.exists();
    QFileInfo info(dbFile);
    qDebug() << info.absoluteFilePath();
    

    This just prints true, "assets:/be_01.jpg".

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean that source: "assets:/be_01.jpg" doesn't work ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        m_andrej
        wrote on last edited by
        #3

        Yes, it doesn't work either.

        From what I found so far it seems that this can't be done :-( So I'm copying the files to current directory after application start.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved