How to load images from rcc binary file
-
wrote on 7 Aug 2018, 11:52 last edited by
I have to work on a lot of images which is causing me a out of memory allocation error. So I have decided to work with External Binary Resources. I have created two qrc files one for my .qml files and other for my images. I have converted my qrc file of images to .rcc and registered the resource. My application is running but the images are not being displayed. What could be the problem and are there any other steps that I need to follow?
My .pro file
QT += quick
QT += texttospeech
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
RESOURCES += qml.qrc -
Show us the paths you define in the QRC file, as well as how you use them in C++ / QML code. You may be using wrong prefix, for example.
-
wrote on 7 Aug 2018, 13:37 last edited by
QRC code:
<RCC>
<qresource prefix="/">
<file>images/left_gauge.png</file>
<file>images/left_gauge_bar.png</file>
</qresource>
</RCC>C++ Code:
QResource::registerResource("qml_image.rcc");QML usage
source: "images/left_gauge.png"
-
QRC code:
<RCC>
<qresource prefix="/">
<file>images/left_gauge.png</file>
<file>images/left_gauge_bar.png</file>
</qresource>
</RCC>C++ Code:
QResource::registerResource("qml_image.rcc");QML usage
source: "images/left_gauge.png"
@adi619 said in How to load images from rcc binary file:
C++ Code:
QResource::registerResource("qml_image.rcc");This is not necessary if you already register your resource in .pro file.
QML usage
source: "images/left_gauge.png"
That should be:
source: ":/images/left_gauge.png"
-
wrote on 7 Aug 2018, 13:49 last edited by
Same error continues
QML Image: Cannot open: qrc:/:/images/left_gauge.png -
Oh so QRC is already there in the path. You don't need the
:/
then.Are you sure the image was compiled into the resource? Is there really a file at
images/left_gauge.png
relative to QRC file location (when building project)? -
wrote on 7 Aug 2018, 14:06 last edited by
The Images are getting loaded when I have added
RESOURCES += qml.qrc
qml_image.qrcBut again then these are not linked with .rcc the binary file. This gives me memory issues when I add more images.
-
Hi,
How many images are you trying to load in memory ?
How big are they ? -
The Images are getting loaded when I have added
RESOURCES += qml.qrc
qml_image.qrcBut again then these are not linked with .rcc the binary file. This gives me memory issues when I add more images.
@adi619 said in How to load images from rcc binary file:
The Images are getting loaded when I have added
RESOURCES += qml.qrc
qml_image.qrcBut again then these are not linked with .rcc the binary file. This gives me memory issues when I add more images.
Oh OK you want to load them separately. Then make sure your registration points to a valid file:
const QString path("qml_image.rcc"); if (!QFileInfo::exists(path)) qFatal("Could not load image resource!"); QResource::registerResource(path);
Alternatively, divide your QRC file into several smaller files - then it won't use as much memory during compilation.
1/9