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

查看:575
本文介绍了更改后,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时会重新编译它们,重新构建或清理并构建,以便可以看到自己的更改。结果在我的构建目录中,我看到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! *****************************************************************************/

静态const无符号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 0xed,0xa4,0xde,0xa0,0x77,0xf0,0xba,0x49,0x63,
0x20,0x45,0xda,0xda,0x68,0x1e,0xe,0x45,0xc1,0x95,0xa8,0x15,0x2f, 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命令创建脚本文件(对我来说,这是我在MAS OS上工作时的.sh文件,对于Windows将是.bat文件)。就我而言,它包含两行:

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

#!/bin/sh

Touch qml.qrc

Touch 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天全站免登陆