Tip of the day – Make Qt Creator to compile QML files to resource file on every build

I like to distribute my QML application so that everything comes with a single binary executable. In practice this means that I have defined that all my QML files are compiled into binary using Qt’s resource compiler. Resource system in Qt is quite nice, but there is annoying bug in Qt creator. Sometimes it doesn’t recompile resources even though I have modified a QML file. This means that you need to select “Clean” and “Build” from Qt creator in order to get modifications compiled. This takes time.

Some time ago, I figured out a workaround for this. You can add a custom build step to your Qt Creator’s project. This build step modifies e.g. an image that is included the project and then resources are recompiled. Here’s a screenshot how you can do it.

Custom build step to make rcc run every time you compile.

I added the custom build step to the first (touch quickflickr.png) and when my project is being compiled it notices that some of the resources have changed and it runs resource compiler too. This is far from an elegant solution, but at least it works for me and I don’t need to run “Clean & Build” which takes for ever. At least, it feels so after you have recompiled your project for the 10th time.

UPDATE: I thought, that there would have been a bug about this but couldn’t find a onet from Qt’s issue tracker so I created a new one: QTCREATORBUG-5743.

I hope this trick will help some one else too. Thanks for reading my blog and thanks for Bale to encourage me to write this “tip of the day” post. Cheers!

Tags: , ,

4 Responses to “Tip of the day – Make Qt Creator to compile QML files to resource file on every build”

  1. dubik says:

    Every time you add qml file just execute “run qmake” and it will recompile everything properly.

    • zchydem says:

      @dubik Thanks for the comment!

      The problem is not adding the QML file to resource and it doesn’t get compiled in. The problem is that if I modify any of the existing QML files in my project (they already were added to resource file and compiled earlier) the modified files won’t get compiled into a binary.

      I also want to mention that this problem doesn’t happen every time. Sometimes I have worked on my project for 2 hours and all the suddenly it quits compiling my changes. Usually this doesn’t happen for all the files i.e. modifications in a one file get compiled and modifications in other file won’t get compiled in.

      I haven’t tried to run qmake, but as you proposed, I believe it works too.

  2. ducvd says:

    I followed your instruction. But it seems the QT compiler does not re-compile the changed QML files.

    Even if I manually run command “touch home.png” (home.png is a image file in resource (.qrc file)), nothing happens.

Leave a Reply

You must be logged in to post a comment.