Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

qt - Load qmldir from QRC file

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...