Qt World Summit: Submit your Presentation

Could Qt resource compiler (RCC) generate dependencies?

  • It seems there is no way to call Qt resource compiler (RCC) so that it only generates a list of resource files the .qrc file depends on. While such a feature is useful for creating efficient build scripts.

    I know that .qrc file format is simple and you could just extract the resource file with an XPath expression. But still it would be simpler and more elegant for the tool itself to offer such functionality. Especially that it seems that .qrc file format is not “official” - you can have a look and see what it is but there is no guarantee it will not change later. (And also this is a double edged sword: if generating the list is simple then adding such switch to RCC should be easy as well!)

    What do you think about it?

  • Lifetime Qt Champion


    Can you elaborate on your use of such information ? And on the build scripts part ?

  • If I know to which resource files a .qrc file refers to (lets call them “additional dependencies”) then I can make a better build script so that RCC is called for a .qrc file if either the .qrc file changed (obvious!) or any of its additional dependencies changed.

    I think it would be done mostly useful if RCC accepted an additional file path argument that if present would point to a file to which additional dependencies (paths to resource files) should be output. That way when first compiling .qrc file we would do “full run” and get resulting .cpp file and those additional dependencies. When building later we will read the additional dependencies file (the clue is that it stores less information for internal use only so it could be much simpler) and then see if the .qrc or any of those additional dependencies files are newer than resulting .cpp file and if so build again. Otherwise skip.

    The issue to decide are for example: (1) should RCC allow either dependencies generation or normal work or maybe both at once? (I would go for both at once if such are the arguments), (2) what should be format of the generated additional dependencies? (I would go for simple text file containing a single file path in every line).

    I’m working on better support for Qt in MSBuild (projects generated by Qt Plugin have some issues). And no I have to read those dependencies by my own using XPaths expressions. But that doubles the work (as compared to RCC doing that in single run) and makes me depend on .qrc file format which is nowhere specified or official (as it seems to me).

    (Yeah, the same request could probably be made on UIC and MOC. But lets start with simpler things.)

  • Lifetime Qt Champion

    I must say I don't see your point in having additional dependencies for the resources since adding a new dependency is essentially updating the qrc file.

    Why not help improve the plugin rather than reinvent the wheel ? The goal of this plugin is to allow a comfortable MSVC Qt experience, if you have found issues with the MSVC plugin you should report them or discuss them on the mailing list so everybody would benefit

  • I don't understand your reply... Maybe referring to some other example could make me more clear.

    For a given source (.cpp) file to make an efficient build script you have to know which header files (.h[pp]) does it include (directly or indirectly). If you don't know that then modifying even a single header file requires you to rebuild everything (rather than just those source files that were actually affected). In large projects the difference in building time is huge.

    With the .qrc file it is just the same. The scale of the issue is not as big since .qrc files are just a few at most and their resources change rarely. (And also extracting those dependencies is much easier for .qrc.) But still it is the same issue.

    Qt Plugin could be easily made much better by using more MSBuild and thus make resulting projects smaller, more maintainable and easier to use and adjust. But I'm not sure if this could be done easily from a plugin "point of view".

    And anyway I think that Qt Plugin authorities do know what they do and why they do it. MSBuild (in Visual 2010) is not that new anymore...

    Finally after all I do write in a public forum so where else should I write?

  • Lifetime Qt Champion

    I think I'm starting to better understand your ideas.

    What I was saying is that If you have new ideas/solutions to better integrate Qt in MSVC, you should bring them to the development mailing list. You could then discuss them with the guys behind the plugin. That might benefit all Visual Studio Qt users.

    This forum is more user oriented so you might not get the feedback you are searching

  • You can use rcc itself to 'extract' the list of files in the .qrc by running rcc -list foo.qrc. However, this should not be needed, as qmake takes care of those dependencies when generating the Makefiles. So it should "just work". So what kind of build system exactly are you trying to set up, what did you try, and how did that fail?

  • Right now Qmake doesn't generate these dependencies and this is very inconvenient if you are using QML in QRC files. I am working with xCode and have yet to to figure out a decent way besides rebuilding the Xcode project from scratch to get QML file changes to be picked up. Very inefficent.

  • Is 'rcc -list some.qrc' what you are looking for?

  • I've been trying to do exactly the same thing. I didn't know about rcc -list, so in the past I've used a "sed" hack extracting the files directly from the .qrc. Now I've rewritten this as:

    %.d: %.qrc
    $(RCC) -list $< | sed -n 's%([^[:space:]].)%qrc_$.cpp: $(dir $<)\1%p' > $@

    That's a GNU make rule to create a file <resources>.d containing all dependencies - which accompanies

    qrc_%.cpp: %.qrc
    $(RCC) $< -o $@

    for the actual resources compilation. (No I'm not using qmake, for reasons I won't go into here.)

    It would be better still if rcc itself could add the dependency stuff, though, i.e. prepend "qrc_resources.cpp: " or whatever to each file listed.

  • Note that the "$(dir $<) " shouldn't be there. The point was to prepend the .qrc path to file names, in case it's located on another directory - as paths within the file will be relative to that directory. However, 'rcc -list' will in fact itself add input file directory component as necessary.

  • The --list option does exactly what I asked for.

    Yet I think it was added after I asked the question (or possibly in sources directly as I could have used a distributed version at that time).

    I need this option to generate dependencies for MSBuild. I'm not using qmake.

  • I get a bad feeling when I see replies that keep asserting “you don't need that because qmake…” or “just use the VS plug-in”.

    VS plug-in’s don't work on the Express edition and are not useful for bare MSBuild uses. Some of us need to integrate Qt stuff with existing complex builds, not redo a complex build system with Qt as the boss.

    Seeing as I can't make notes to doc pages, could someone please update the page http://qt-project.org/doc/qt-5/rcc.html to show all the options?

  • @Adam-Badura Though this thread is very old, I actually ran across it when trying to define a custom qmake rcc compiler for pyrcc5 which compiles resources to python byte code in PyQt5. The problem is that I wanted to use the target.depend_command to list out the resource files needed for the resource compiler. This is crucial for editing qml files and having the change picked up in a call to make. rcc -list works perfectly for this.

    For the record, here is my custom compiler:

    pyrcc5.input = RESOURCES
    pyrcc5.output = qrc_${QMAKE_FILE_BASE}.py
    pyrcc5.dependency_type = TYPE_RCC
    pyrcc5.depend_command = rcc -list ${QMAKE_FILE_NAME}
    pyrcc5.CONFIG = no_link target_predeps dep_lines add_inputs_as_makefile_deps
    pyrcc5.commands = pyrcc5 ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

    (And here is my custom pyuic5 compiler:)

    pyuic5.input = FORMS
    pyuic5.output = ${QMAKE_FILE_BASE}_form.py
    pyuic5.dependency_type = TYPE_UI
    pyuic5.CONFIG = no_link target_predeps dep_lines
    pyuic5.commands = pyuic5 ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
    pyuic5.variable_out = GENERATED_FILES
    pyuic5.name = PyUIC5 ${QMAKE_FILE_IN}

Log in to reply