Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] import components from qrc



  • Hi.

    I'm using qrc for my qml files. My main.qml is loaded from main.cpp
    @
    view.setSource( QUrl( "qrc:/qml/main.qml" ));
    @

    I try to import my qml-component in main.qml from qrc too. Disk path to qml-files is ".../qml/main.qml" and ".../qml/Component.qml". Qrc-prefix is "/".

    That's how I try to import:
    @
    import "Component"
    // or
    import "Component.qml"
    // or
    import "qrc:Component"
    // or
    import "qrc:Component.qml"
    // or
    import "qrc:/Component"
    // or
    import "qrc:/Component.qml"
    // or
    import "qrc:/qml/Component"
    // or
    import "qrc:/qml/Component.qml"
    @

    And nothing works. Need help.


  • Moderators

    Hi,

    Try avoiding to keep QML filename as Component since Component is a predefined type.

    Now, you can directly use the QML file instead of importing.
    For e.g
    If your QML file in qrc is say for e.g NewComponent.qml
    then in main.qml you can use directly

    @
    NewComponent
    {
    id: comp
    }
    @



  • "To use the resource system in a mixed QML/C++ application: ......":http://doc-snapshot.qt-project.org/qdoc/qtquick-deployment.html

    put your qml files into resource and then no needd use ""qrc:" in your qml code.



  • Thanks for your replies. Solved.


Log in to reply