Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to load images from rcc binary file
Forum Update on Monday, May 27th 2025

How to load images from rcc binary file

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 1.9k 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.
  • A Offline
    A Offline
    adi619
    wrote on 7 Aug 2018, 11:52 last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 7 Aug 2018, 12:42 last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adi619
        wrote on 7 Aug 2018, 13:37 last edited by
        #3

        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"

        S 1 Reply Last reply 7 Aug 2018, 13:41
        0
        • A adi619
          7 Aug 2018, 13:37

          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"

          S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 7 Aug 2018, 13:41 last edited by
          #4

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

          (Z(:^

          1 Reply Last reply
          1
          • A Offline
            A Offline
            adi619
            wrote on 7 Aug 2018, 13:49 last edited by
            #5

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 7 Aug 2018, 13:55 last edited by
              #6

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

              (Z(:^

              1 Reply Last reply
              0
              • A Offline
                A Offline
                adi619
                wrote on 7 Aug 2018, 14:06 last edited by
                #7

                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.

                S 1 Reply Last reply 8 Aug 2018, 05:46
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 7 Aug 2018, 17:56 last edited by
                  #8

                  Hi,

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

                  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
                  1
                  • A adi619
                    7 Aug 2018, 14:06

                    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.

                    S Offline
                    S Offline
                    sierdzio
                    Moderators
                    wrote on 8 Aug 2018, 05:46 last edited by
                    #9

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

                    (Z(:^

                    1 Reply Last reply
                    1

                    4/9

                    7 Aug 2018, 13:41

                    • Login

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