从 QRC 文件加载 qmldir [英] Load qmldir from QRC file
问题描述
我正在尝试在 Qt 快速应用程序中使用 QML 材料库.
但是当我尝试使用导入代码时,它说
<块引用>未安装模块材料"`
<前>进口材料0.1
我也试过这个,但似乎不起作用:
<前>导入模块/材料"作为材料qml.qrc
看起来像这样,列出了所有 qmldir
文件:
<qresource prefix="/"><file>main.qml</file><file>modules/Material/qmldir</file><file>modules/Material/Extras/qmldir</file><file>modules/Material/ListItems/qmldir</file><file>modules/QtQuick/Controls/Styles/Material/qmldir</file></qresource></RCC>
main.cpp
#include #include int main(int argc, char *argv[]){QGuiApplication app(argc, argv);QQmlApplicationEngine 引擎;engine.addImportPath("qrc:/");engine.load(QUrl(QStringLiteral("qrc:/main.qml")));返回 app.exec();}
有什么我遗漏的地方,或者在 qrc
文件中不能使用 qmldir
吗?
需要将模块所在的文件夹添加到导入路径中.
在本例中是 qrc:/modules/
.
示例:
engine.addImportPath( "qrc:///modules" );
要使模块工作,您需要有权访问 qmldir
文件,以及其中引用的所有文件.所以需要把库的所有文件都添加到qrc中.
I'm trying to use the QML-material library in a Qt Quick Application.
But when I try to use the import code it says
module "Material" is not installed`
import Material 0.1
I did also try this but that seems not to work:
import "modules/Material" as Material
qml.qrc
looks like this, all qmldir
files are listed:
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>modules/Material/qmldir</file>
<file>modules/Material/Extras/qmldir</file>
<file>modules/Material/ListItems/qmldir</file>
<file>modules/QtQuick/Controls/Styles/Material/qmldir</file>
</qresource>
</RCC>
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.addImportPath("qrc:/");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
Is there something I'm missing or is it not possible to use qmldir
in qrc
file?
You need to add to the import path the folder where the modules are located.
In this case it's qrc:/modules/
.
Example:
engine.addImportPath( "qrc:///modules" );
For a module to work you need to have access to the qmldir
file, but also all the files referenced in it. So you need to add all the files of the library to the the qrc.
这篇关于从 QRC 文件加载 qmldir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!