QT QML resource files do not recompile after changes

后端 未结 2 1385
故里飘歌
故里飘歌 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: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.

提交回复
热议问题