Qt World Summit: Submit your Presentation

Show image from assets in QML

  • 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".

  • Lifetime Qt Champion


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

  • 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.