QT QML resource files do not recompile after changes

后端 未结 2 1350
故里飘歌
故里飘歌 2021-01-17 23:05

I\'m using QT 5.9.1 working on Mac OS. My project is mobile App with C++ logic and QML UI Layer. All QML files are included into qml.qrc file, so in my .pro file I have

相关标签:
2条回答
  • 2021-01-17 23:47

    ok, after hours of digging in QTBUGS traces, stackoverflow and others forums I found solution, which somehow satisfies me..

    1) Create script file (for me it's .sh file as I working on MAS OS, for Windows it will be .bat file) with "touch" command to qml.qrc file. In my case it contains 2 lines :

    #!/bin/sh

    Touch qml.qrc

    2) Add Custom build step (Projects->Build Settings->Build Steps->Add Custom Process Step). Choose your created .sh file, choose working directory when you build is located. Make this custom step to be the first executed (before qmake and Make)

    3)So, now changes in qml resource files will be compiled every time you build the project. Script will firstly touch our qml.qrc file, which will refresh it's modified date, so that qml.qrc (hence, our qml resources too) will be added to makefile dependencies.

    it seems to be pretty rough way to solve the problem, but at least you don't have to Clean, Rebuild and so on..

    If someone have better solution, please let me know)

    0 讨论(0)
  • 2021-01-17 23:56

    Unfortunately, the solution given in a link provided in the comments seems to be incomplete and/or broken. But it can be done like this:

    update_qml.target = qml.qrc
    update_qml.commands = echo>>$${update_qml.target} # same as touch
    update_qml.depends = $$files(path/to/resource/files/*, true) # recurse into subdirs
    QMAKE_EXTRA_TARGETS += update_qml
    PRE_TARGETDEPS += $${update_qml.target}
    

    For those who interested in how it works, QMAKE_EXTRA_TARGETS produces the following Makefile rule:

    qml.qrc: file1 file2 ...
            echo>>qml.qrc
    

    So issuing a command make qml.qrc will update the timestamp of qml.qrc as needed. However, to save us from manual typing it every time, we also make use of PRE_TARGETDEPS which fixes the main building rule:

    $(DESTDIR_TARGET): qml.qrc $(OBJECTS) and other stuff ...
            $(LINKER) flags objects and other stuff ...
    

    So now make utility will scan the previous rule every time while building the target.

    0 讨论(0)
提交回复
热议问题