External protected resources

  • hello dear programmers .
    as the title said i need to use a external resources file for my project.
    the case is that i have a gallery ,designed and ready but i used Qresource files (.qrc)
    to handle my image + videos.
    the problem is that qrc files in the final compile turn into 1 solid ".exe" which has a
    huge size and it will get bigger because i need to update it's content later on.
    so any suggestion guys?

  • Moderators

  • ThnQ sir ,i compiled my qrc files into one rcc file.
    but i didn't understood the registerResource part.
    i changed the

    RESOURCES += \


    RESOURCES += \

    and compiled my code again ,now all the images and videos are not loaded.
    i think i should change the typical addresses that i used in my application but don't know how.
    example :

    QPixmap image(":/new/prefix1/imgs/1_02.jpg")

  • Moderators

    as written on the doc page you need to use QResource::registerResource("/path/to/myresource.rcc"); instead of setting it via the RESOURCES qmake variable. Since you do not want it to be compiled into the binary.

  • well i removed

    RESOURCES += \

    from the .pro so the resources won't compile into binary .that worked well ,my .exe size decreased about 10 times.
    now i have to use QResource in my code to address the files in the code.

    QResource b;

    now there is one .qrc file in the images.rcc.
    how should i address the code below for example?

    QMovie *movie = new QMovie(":/new/prefix1/imgs/1.gif");

  • Moderators

    exactly like you did before.
    If the files are still not loaded there is something wrong with your path. Check the bool return value of registerResource().

    On what platform are you on? Note that the path (/images.rcc) you've posted means different things on unix and windows for example.

    btw. you do not need to create a QResource instance. registerResource() is a static method.
    So use it as i've written (QResource::registerResource()) is enough.

  • @raven-worx
    i use windows .
    well now i have the code below in my main.cpp


    also i checked the bool return value and you were right output is false.


    but i checked every where i could for the images.rcc include :
    release folder
    debug folder
    build folder
    main folder which the original cpp and header files are stored.

  • Moderators

    you called the rcc command in some folder, probably it's there (when you didn't change the -o parameter to contain a path).

  • @raven-worx
    i know where is the rcc file ,i changed the location of images.rcc to the
    release folder
    debug folder
    build folder
    main folder which the original cpp and header files are stored.
    There must be something wrong with accessing the file because im pretty sure the
    path "/file.format" will lead to the build folder.

  • Moderators

    It depends where the current working directory is set at the time of calling.
    You can check with QDir::currentPath()

  • ThnX Again @raven-worx
    it was pointing to entirely diffresnt drive
    my project path is
    pretty much confusing ,huh?
    i started the project on Qt 5.2 ,ended up on Qt 5.7 for the android compiler and newer version.
    QDir::currentPath() showed me that the current working directory was not there.
    changed the directory of project to there and problem solved.

  • Qt Champions 2016

    Just as a note.
    There is also
    Debug() << "App path : " << qApp->applicationDirPath();

    Which is where exe is. So I use that for loading files "next" to the exe no matter where is is.
    debug/release or deployment folder.

Log in to reply

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