Qt5 QML将资源组织到文件夹中

时间:2016-02-17 15:04:18

标签: qml qt5

我想将一些.qml文件放入文件夹中。

这有效,

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
        <file>other/Thing.qml</file>
    </qresource>
</RCC>

但这并不是

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
    </qresource>

    <qresource prefix="/other">
        <file>other/Thing.qml</file>
    </qresource>
</RCC>

即时分离,因为下一步是移动&#34; /其他&#34;将资源放入单独的qrc文件中。

任何帮助?感谢。

编辑1:

我试试这个,

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
    </qresource>
    <qresource prefix="/other">
        <file>other/Thing.qml</file>
        <file>other/qmldir</file>
    </qresource>
</RCC>

qmldir:

module Other
Thing 1.0 Thing.qml

然后添加到main.qml:

import Other 1.0

编辑#2

我尝试添加到main.cpp:

engine.addImportPath("other");

engine.addImportPath("qrc:/other");

没有。

https://gist.github.com/anonymous/9d82204dac684263e257

2 个答案:

答案 0 :(得分:1)

修复方法是在资源中添加导入路径

engine.addImportPath("qrc:/Other");

文件设置在这里,

https://gist.github.com/anonymous/314e95bc6cfc0ed6b3b5

答案 1 :(得分:0)

我认为您在引用“其他”文件夹时遇到的问题与字母差异有关。您有时使用“其他”,有时使用“其他”。

试试这个:

import other 1.0;

而不是

import Other 1.0;

似乎qt考虑了文件夹的真实姓名,而不是qmldir中指定的名称。