How to load images from rcc binary file



  • 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


  • Moderators

    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.



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


  • Moderators

    @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"
    


  • Same error continues
    QML Image: Cannot open: qrc:/:/images/left_gauge.png


  • Moderators

    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)?



  • The Images are getting loaded when I have added

    RESOURCES += qml.qrc
    qml_image.qrc

    But again then these are not linked with .rcc the binary file. This gives me memory issues when I add more images.


  • Lifetime Qt Champion

    Hi,

    How many images are you trying to load in memory ?
    How big are they ?


  • Moderators

    @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.qrc

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.