Load qmldir from QRC file

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

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:

main.qmlmodules/Material/qmldirmodules/Material/Extras/qmldirmodules/Material/ListItems/qmldirmodules/QtQuick/Controls/Styles/Material/qmldir

main.cpp

#include  #include   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?

回答1:

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.



转载请标明出处:Load qmldir from QRC file
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!