Download qmldir from a QRC file

I am trying to use a library of QML materials in a fast Qt application.

But when I try to use the import code, it says

module "Material" is not installed`

  import Material 0.1

I tried this too, but it doesn't seem to work:

  import "modules / Material" as Material

qml.qrc as follows: 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 am missing or impossible to use qmldir in a qrc file?

+6
source share
1 answer

You need to add to the import path the folder where the modules are located.

In this case, it is qrc:/modules/ .

Example:

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

For the module to work, you need to have access to the qmldir file, but also all the files to which it refers. Therefore, you need to add all library files to qrc.

+8
source

All Articles