K
K
Kastuś2018-07-05 18:33:25
QML
Kastuś, 2018-07-05 18:33:25

Qml import does not find different directories?

I want to take out a part of qml files for the project.
is:
rootdirectory / myproject / rs /main.qml
rootdirectory / myproject / myproject.pro
rootdirectory / qml / item.qml
how to import in main.qml -> item.qml ?
Did:
import "../../qml" (finds properties in the project, etc. but swears)
import "../../qml/"
import "../../qml/*"
import "qrc: /qml" (registered file alias = "qml/item.qml")
error: no such directory
import "/home/PC/rootdirectory/qml"
import "/home/PC/rootdirectory/qml/"
import "/home/PC /rootdirectory/qml/*"
error:
there are 2 programs and 70% of the total code

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kastuś, 2018-07-05
@Gytim

In general, I was a little inattentive. 1 of the options works (I didn’t have pictures yet and cursed):
in qrc

"<resource="qml">
"<file alias="qml/main.qml">rc/main.qml</file>
"<file alias="qml/item.qml">../../qml/item.qml</file>

in QML main.qml
import "qrc:/qml"

4
4rtzel, 2018-07-05
@4rtzel

In my opinion, qml is not very good at dealing with relative paths that go beyond the root of the project. Try something like this:
Structure:

├── qml
│   └── MyItem.qml
└── project
    ├── main.cpp
    ├── main.qml
    ├── qml.qrc
    ├── project.pro

main.qml:
import "qml" as Common // Просто "qml"; без "../"

Window {
    visible: true
    width: 640
    height: 480
    Common.MyItem {
    }
}

Don't forget to add files to qml.qrc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question