Show image from assets in QML
-
wrote on 21 Jul 2015, 12:41 last edited by m_andrej
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 withassets:/
. 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"
. -
Hi,
Do you mean that
source: "assets:/be_01.jpg"
doesn't work ? -
wrote on 22 Jul 2015, 07:24 last edited by
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/3