SGbo
SGbo

Reputation: 344

qml hierarchy with qrc

I'm programming a c++/qml application. Since I have many qml-files I wanted to make a directory structure. I already implemented the structure in my filesystem like this:

project
    |- qml
        |- main.qml
        |- widgets
            |- Button.qml
            |- Label.qml

What I now want to do is to use qrc-prefixes to create exactly the same hierarchy:

main.qrc
    /
        main.qml
    /widgets
        Button.qml
        Label.qml

This is my example qml-file:

import QtQuick 2.2

import "widgets"

Item {
    id: window
    width: 800
    height: 480

    Button {
        id: button
        anchors.centerIn parent
        text: "click me"
    }
}

The problem I have, is that the compiler does not know the Button!

EDIT:

Error Message: qrc:///qml/main.qml:4 "widgets": no such directory

Upvotes: 7

Views: 1106

Answers (2)

Joel Sampson
Joel Sampson

Reputation: 51

Make sure that you add the directories to the qrc file. The simplest way to do that is to right click on your "qml.qrc" file in QtCreator and select "Add Existing Directory". Following that prompt should also help the QML interpreter find your files.

Upvotes: 1

KimKulling
KimKulling

Reputation: 2833

The QML-interpreter tries to load your directory at the false place ( filesystem instead of qrc-file ). Try

import "qrc:/widgets"

to solve your issue.

Upvotes: 6

Related Questions