7

There are x number of .png files in a directory.
Instead of adding all these manually I would want to specify the directory path in the .qrc file and let it include all of them on its own.

What is the way to achieve this?

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
  • 1
    The resource file is not filled during runtime, this means you cannot just add codelines to add the files automatically. But you can actually add many files at once by simply selecting the files. Nevertheless adding files afterwards to the selected path requires you to manually ad the files in the resource file. – Sebastian Lange Jan 14 '15 at 07:37

4 Answers4

6

Here is a little bash script that generate a qrc file from the content of a folder

#!/bin/sh
QRC=./resourcefilename.qrc
echo '<!DOCTYPE RCC>' > $QRC
echo '<RCC version="1.0">' >> $QRC
echo '  <qresource>' >> $QRC

# for each files/folder in the folder "theFokderName"
for a in $(find theFolderName -d)
do
    # if this is not a folder
    if [ ! -d "$a" ]; then
        echo '      <file>'$a'</file>' >> $QRC
    fi
done

echo '  </qresource>' >> $QRC
echo '</RCC>' >> $QRC

You can easily customize it.

frachop
  • 191
  • 1
  • 7
5

No, this is not yet possible, see this bugreport for details.

Thomas McGuire
  • 5,308
  • 26
  • 45
2

Just for documentation, I found a workaround to this on this link.

The following entry in project.pro ensures that the resources are built into the application binary, making them available when needed:

RESOURCES += \
    qml/main.qml \
    images/image1.png \
    images/image2.png

A more convenient approach is to use the wildcard syntax to select several files at once:

RESOURCES += \ 
    $$files(qml/ *.qml) \
    $$files(images/ *.png)

So, if you use $$file(wildcard) on your .pro file, it would work. I tried and it worked OK.

riQQ
  • 9,878
  • 7
  • 49
  • 66
Cmorais
  • 41
  • 2
0

If you’re using qmake you can simply reference the folder containing your assets like this in your project file:

RESOURCES += images/

No need to use scripts or even the $$files() helper, unless you want to glob by file extension.

Frederik
  • 467
  • 6
  • 16