QT QML 资源文件在更改后不会重新编译 [英] QT QML resource files do not recompile after changes

查看:42
本文介绍了QT QML 资源文件在更改后不会重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mac OS 上使用 QT 5.9.1.我的项目是具有 C++ 逻辑和 QML UI 层的移动应用程序.所有 QML 文件都包含在 qml.qrc 文件中,所以在我的 .pro 文件中有

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

资源 += qml.qrc

在qml.qrc里面有一个我在Project中使用的所有资源文件的列表,比如图片、图标和QML文件,在QT Creator中显示OK:

Inside qml.qrc there is a list of all resource files I use in Project, such as pictures, icons and QML files, in QT Creator it's displayed OK:

你可以看到一些 QML 文件位于 qml.qrc 的根路径中,而其他文件位于子文件夹中,例如qrc:/Elements/".

As you can see some QML files are located in ROOT path of qml.qrc when other files are in subfolders , e.g. "qrc:/Elements/".

所以问题是,当我对位于 qml.qrc 根目录中的文件进行更改时,它们通常会在我按下 build、rebuild 或 clean and build 时重新编译,因此我可以看到我的更改.结果,在我的构建目录中,我看到 qml_qrc.cpp(据我了解,此文件包含我的资源文件的 cpp 表示并用于编译它们)文件已刷新,我的更改已应用并且一切正常.

So problem is that whenether I make changes in Files that located in root of qml.qrc - they are normally recompiled when I press build, rebuild, or clean and build, so I can see my changes. As a result in my build directory I see that qml_qrc.cpp (as I understand this file contains cpp representation of my resource files and is used to compile them) file is refreshed,my changes are applied and everything is OK.

这里只是这个文件的一部分,它以 MainPage.qml 资源文件的 cpp 十六进制表示开始.

Here is just piece of this file, which begins with cpp hex representation of MainPage.qml resource file.

/************************************************************************************ 资源对象代码**** 创建者:Qt 版本 5.9.1 的资源编译器**** 警告!在此文件中所做的所有更改都将丢失!************************************************************************************/

/**************************************************************************** ** Resource object code ** ** Created by: The Resource Compiler for Qt version 5.9.1 ** ** WARNING! All changes made in this file will be lost! *****************************************************************************/

static const unsigned char qt_resource_data[] = {///Users/admin/QtProjects/LazuritApp-temp/MainPage.qml
0x0,0x0,0x7,0xd1, 0x0,
0x0,0x1e,0xbb,0x78,0x9c,0xd5,0x19,0x5d,0x6f,0xdc,0x36,0xf2,0x7d,0x7f,0x5,0x6f,0xb,0x14,0xbb,0x69,0xa2,0xf5,0xae,0xed,0xa4,0xde,0xa0,0x77,0xf0,0xba,0x49,0x63,0x20,0x45,0xda,0xda,0x68,0x1e,0xe,0x45,0xc1,0x95,0xa8,0x15,0x2f,0x5a,0x51,0xa5,0x24,0xdb,0x5b,0xc3,0x40,0xda,0x2,0xed,0x1,0x79,0x28,0x70,0x68,0x71,0xcf,0xf7,0xf,0xdc,0xbb,0x6b,0x1b,0x34,0x4d,0xfa,0x17,0xb4,0xff,0xa8,0x43,0x52,0x5f,0x94,

static const unsigned char qt_resource_data[] = { // /Users/admin/QtProjects/LazuritApp-temp/MainPage.qml
0x0,0x0,0x7,0xd1, 0x0,
0x0,0x1e,0xbb,0x78,0x9c,0xd5,0x19,0x5d,0x6f,0xdc,0x36,0xf2,0x7d,0x7f,0x5,0x6f, 0xb,0x14,0xbb,0x69,0xa2,0xf5,0xae,0xed,0xa4,0xde,0xa0,0x77,0xf0,0xba,0x49,0x63, 0x20,0x45,0xda,0xda,0x68,0x1e,0xe,0x45,0xc1,0x95,0xa8,0x15,0x2f,0x5a,0x51,0xa5, 0x24,0xdb,0x5b,0xc3,0x40,0xda,0x2,0xed,0x1,0x79,0x28,0x70,0x68,0x71,0xcf,0xf7, 0xf,0xdc,0xbb,0x6b,0x1b,0x34,0x4d,0xfa,0x17,0xb4,0xff,0xa8,0x43,0x52,0x5f,0x94,

.......

但是如果我更改位于子文件夹中的那些资源文件,qml_qrc.cpp 文件不会刷新,因此我的资源文件不会重建,即使我尝试清理,然后重建.即使我手动运行 qmake"然后重建.在这种情况下,唯一有帮助的方法是手动删除构建文件夹(或者更准确地说,您可以删除 qml_qrc.cpp 文件).因此,然后按构建"将创建新的 qml_qrc.cpp 文件,该文件将包含正确的代码,以及我在资源文件中所做的更改.

But if I change those resource files located in subfolders, qml_qrc.cpp file is not refreshed, so my resource files are not rebuild, even if I try Clean, then rebuild. Even if I do "run qmake" manually and then rebuild. The only thing helps in this situation - to manually delete build folder (or to be more precisely you can just delete qml_qrc.cpp file). So then pressing "Build" will create new qml_qrc.cpp file, which will contain correct code, with changes I've done in my resource files.

谁能帮助我或解释为什么会发生这种情况以及在这种情况下我该怎么办?手动删除并重建很烦人,但是将所有资源文件放在项目的根路径中也不是一个好的决定...

Can someone help me or explain why this happens and what can I do in this situation? deleting manually and rebuilding is annoying, but placing all resource files in root path of project is also not a good decision...

我也尝试过粘贴

更新 qml

qml_scenes.depends = $$PWD/QML Files/OrdersPage.qml

qml_scenes.depends = $$PWD/QML Files/OrdersPage.qml

qml_scenes.commands =QMAKE_EXTRA_TARGETS += qml_scenes

qml_scenes.commands = QMAKE_EXTRA_TARGETS += qml_scenes

如上所述 这里,但没有帮助

as was described here, but it didn't help

推荐答案

好的,在 QTBUGS 跟踪、stackoverflow 和其他论坛中挖掘了几个小时后,我找到了解决方案,这让我很满意..

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

1) 使用 qml.qrc 文件的touch"命令创建脚本文件(对我来说,它是 .sh 文件,因为我在 MAS OS 上工作,对于 Windows,它将是 .bat 文件).就我而言,它包含 2 行:

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

触摸qml.qrc

2) 添加自定义构建步骤(项目->构建设置->构建步骤->添加自定义流程步骤).选择您创建的 .sh 文件,在构建时选择工作目录.将此自定义步骤设为第一个执行(在 qmake 和 Make 之前)

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)因此,现在每次构建项目时都会编译 qml 资源文件中的更改.脚本会首先接触我们的 qml.qrc 文件,它会刷新它的修改日期,这样 qml.qrc(因此,我们的 qml 资源也是)将被添加到 makefile 依赖项中.

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)

这篇关于QT QML 资源文件在更改后不会重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆