Paul Masri-Stone
Paul Masri-Stone

Reputation: 3139

In Qt, when should you use RESOURCES vs. DISTFILES vs. OTHER_FILES

Within the .pro file, things are straightforward if you're including header files (use HEADERS), C++ files (use SOURCES) and Objective-C / Objective-C++ files (use OBJECTIVE_SOURCES), but it is less clear to me how other file types should be included.

e.g. looking at various examples that Qt provide, there is inconsistency about whether QML files should be DISTFILES, OTHER_FILES or contained within a .qrc file (i.e. RESOURCES). I've gone with putting QML files in a qml.qrc file.

My question has arisen because I'm including data files, such as audio .wav files, within a .qrc file (also as shown in Qt examples; e.g. Qt Quick Demo - Maroon in Trouble) but this has slowed compiling down to a crawl. And in the case of MinGW on Windows, it simply crashes with an out of memory error when it reaches 1GB. There must be a better way to include these!

Could you provide a guide as to when to use:

Upvotes: 25

Views: 16127

Answers (3)

Felix
Felix

Reputation: 7146

  • DISTFILES: Something special for unix you won't use in most cases. From the docs:

Specifies a list of files to be included in the dist target. This feature is supported by UnixMake specs only.

  • OTHER_FILES: Files, that are part of you project, but not of the "build". This can be things like a readme, build hints, or any other stuff, that does not fit into any other categories
  • RESOURCES: .qrc-files, that will be compiled into the application.

Regarding the usage of those three with QML:
You can basicly use DISTFILES or OTHER_FILES for other files. In QtCreator the appear in a node as other files. These two are exchangeable for most developers. The Qt examples are local project, thus either they don't require a resource or have both, i.e. you can find the QML-files in for example OTHER_FILES and RESOURCES.

For QML files, you should always use RESOURCES, to make sure they are within your binary.

Upvotes: 6

li ki
li ki

Reputation: 382

Speaking of DISTFILES , you can try it yourself.

Assuming you are using Qt on Windows. Here is a very simple qmake project file project.pro:

TEMPLATE = app

DISTFILES += "C:\Windows\explorer.exe"

qmake it, and you can find the following statements in generated Makefile.Debug and Makefile.Release:

DIST          = C:\Windows\explorer.exe

...

dist:
    $(ZIP) project.zip $(SOURCES) $(DIST) project.pro
    ...

The target dist is one of the standard targets. I learned it from makefile - What is the difference between make and make dist? - Stack Overflow.

Upvotes: 0

maxik
maxik

Reputation: 1123

Quoting from the qmake manual:

RESOURCES

Specifies the name of the resource collection files (qrc) for the target. [...]

DISTFILES

Specifies a list of files to be included in the dist target. This feature is supported by UnixMake specs only. [...]

OTHER_FILES

This seems in fact undocumented, at least I could not find anything. As far as I can tell all files listed here are only linked in project explorer (of Qt Creator for example) and are not treated in any way by qmake.


As for your example you might consider shipping the files as they are and not include them in any resource file, because they are compiled into the binary.

You may also take a look at compiling external resources and using them for your large files to keep the simplicity of Qt's resource system.

Upvotes: 18

Related Questions