1

I'm on a project that used to have Compiled-in Resources.

Now, the user can choose the theme that he wants to work on. No problems until there, in a little research I started to use the External Binary Resource approach.

My resources were build successfully and the QResource::registerResource("/path/to/myresource.rcc"); returns true.

It is not working properly though. Apparently the compiled-in resource is still there, in the executable. I can't see the different icons stored in my external binary resource.

How do I remove this compiled-in resource? Do I need to do that to work properly?

2 Answers 2

3

Assuming you are using a .pro file for your project, you need to remove the resource file from the RESOURCES list. If you still want it to be listed in your project, you can use OTHER_FILES.

Before:

RESOURCES += file1.qrc file2.qrc

After:

RESOURCES += file2.qrc
OTHER_FILES += file1.qrc

If you want to go a step further you can automate the build of qrc files:

RCC_BINARY_SOURCES += file1.qrc

asset_builder.commands = $$[QT_HOST_BINS]/rcc -binary ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT} -no-compress
asset_builder.depend_command = $$[QT_HOST_BINS]/rcc -list $$QMAKE_RESOURCE_FLAGS ${QMAKE_FILE_IN}
asset_builder.input = RCC_BINARY_SOURCES
asset_builder.output = $$OUT_PWD/$$DESTDIR/${QMAKE_FILE_IN_BASE}.qrb
asset_builder.CONFIG += no_link target_predeps
QMAKE_EXTRA_COMPILERS += asset_builder

OTHER_FILES += $$RCC_BINARY_SOURCES
Sign up to request clarification or add additional context in comments.

2 Comments

this creates individual rcc files for each qrc. How do we tell it to create one single rcc for multiple qrc's like what happens with cmake : qt_add_binary_resources(resources x.qrc y.qrc OPTIONS -no-compress) results in the following rcc invocation by cmake : rcc -no-compress --binary --name resources --output /Users/xxx/code/roku-qml/app/build/resources.rcc /Users/xxx/code/roku-qml/app/x.qrc /Users/xxx/code/roku-qml/app/y.qrc
@n-mam You should post your own question. Anyway, looking at the combine CONFIG option of qmake should be a good start.
1

You have to change the way the resources are compiled. By default, every resource file (resources.qrc, for example) included in a Qt project is compiled to C++ code (the qrc_resources.cpp you've probably seen after compiling the project). That makes the resource is compiled and linked with your executable (or library). The Qt for Visual Studio plugin does exactly that: adds a custom build step to every QRC file. Open the properties of the QRC file to take a look (right-click on the QRC file, then Properties):

Default compilation of a QRC file

  • Command line: "$(QTDIR)\bin\rcc.exe" -name "%(Filename)" -no-compress "%(FullPath)" -o .\GeneratedFiles\qrc_%(Filename).cpp
  • Outputs: .\GeneratedFiles\qrc_%(Filename).cpp
  • %(Filename) is, as you can figure out, the extension-less name of the file

To avoid this behaviour just remove the QRC file from the project. Of course, the problem is that you'll have to manually build the .rcc file. You can do it using a script as part of your makefile.

On the other hand, if you're using Visual Studio, you can change the command used to compile it, adding the -binary option to the rcc tool so it compiles to an external file. In this way it will be included in your usual compilation workflow: Custom compilation of QRC to RCC

  • Command line: "$(QTDIR)\bin\rcc.exe" -name "%(Filename)" "%(FullPath)" -binary -o "%(Outputs)"
  • Outputs: $(OutDir)\%(Filename).rcc - it is different from screenshot because I took it from an existing project, use the one in the text to place the RCC file in the same dir of your executable.

Important note: be sure you change the build tool for all the configurations.

If you use a makefile or Qt Creator instead, you can use this as a base to create the needed script.

Hope this can help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.