代码之家  ›  专栏  ›  技术社区  ›  iHowell

有没有办法简化qresource文件描述符?

  •  0
  • iHowell  · 技术社区  · 6 年前

    我现在有一个 qml.qrc

    <RCC>
        <qresource prefix="/qml">
            <file>qml/components/Icon.js</file>
            <file>qml/components/IconButton.qml</file>
            <file>qml/components/IconLabel.qml</file>
            <file>qml/main.qml</file>
            <file>qml/setup/NewProject.qml</file>
            <file>qml/setup/Setup.qml</file>
            <file>qml/setup/Startup.qml</file>
            <file>qml/workspace/AnimationWindow.qml</file>
            <file>qml/workspace/DepthChartControls.qml</file>
            <file>qml/workspace/NewAnimationWindow.qml</file>
            <file>qml/workspace/TraceWindow.qml</file>
            <file>qml/workspace/Workspace.qml</file>
            <file>qml/workspace/WorkspaceMenuBar.qml</file>
            <file>qml/Empty.qml</file>
            <file>qml/qmldir</file>
            <file>qml/Style.qml</file>
            <file>icons/play.svg</file>
        </qresource>
        <qresource prefix="/icons">
            <file>lib/material-design/icons/svg/play.svg</file>
        </qresource>
    </RCC>
    

    所以我必须引用qml文件,比如: engine.load(QUrl("qrc:/qml/qml/main.qml")) ,当我想访问图标时,我必须指定 :/icons/lib/material-design/icons/svg/play.svg

    1 回复  |  直到 6 年前
        1
  •  3
  •   Kuba hasn't forgotten Monica    6 年前

    它已经是你想要的样子了。您可以按以下方式访问文件:

    qrc:/qml/Icon.js
    qrc:/icons/play.svg
    

    等。

    一般工作原理如下:给定

    <qresource prefix="PREFIX">
    <file alias="ALIAS">QRC_RELATIVE_FILEPATH</file>
    </qresource>
    

    资源通过

    qrc:PREFIX/ALIAS
    

    ALIAS 是中的文件名(并且只有文件名) QRC_RELATIVE_FILEPATH -例如,在您的示例中使用path元素是多余的,但受支持。