1

I have a .qml file with a component 2 steps above in my project path because I want to have a component folder above many projects to be shared by some of these. So in my main.qml I do:

import 'qrc:/../../components'

That works and I can use my qml component from file. However in the design view, I get the warning:

found not working imports: ...<file and import line number where the import is> "qrc:/../../components": no such directory

Many other things I tried make the project not compile or throwns error at runtime.

Trial1: import "qrc:/": compile time error: Unknown component. (M300). Makes sense as the component is in a path above.
Trial2: import './../../components': runtime error: import "./../../components" has no qmldir and no namespace.
Tried also to put a qmldir file in my components folder where my component is with the text "MyComponent MyComponent.qml" as explained in Importing QML Document Directories

Apart from the warning everything works fine. Project compiles, runs and the changes in the component are shown when I work in the design view.

info:
-> component resource is added to the .qrc resource file, and the file exists (project works)
-> QtQuick version QtQuick 2.9
-> Qt Creator 4.15.2 Based on Qt 5.15.2

How do I get rid of the warning?

Edit: I also tried following the steps of this answer with no success.

Adding the content of my .qrc file:

<RCC>
    <qresource prefix="/">
        ...<other not relevant resources>
        <file>../../components/MyComponent.qml</file>
    </qresource>
</RCC>

Screenshot of the warning:

enter image description here

7
  • Have you set up any prefixes in your .qrc file yet? Could you share a minimal example of the textual contents? And what is the exact line the warning is pointing at, that main.qml one you posted? Commented Dec 13, 2021 at 16:55
  • thanks for your interest @dabbler. Adding the contents of the .qrc in the edited question. The warning points at the line of the import: import 'qrc:/../../components'. Adding also a screenshot of the warning Commented Dec 13, 2021 at 17:10
  • I am fearing that I cannot reference a file component that is located in a path that is above the application root's path, at least I am not finding the way. Having a copy of the file for each of the applications solves the problem, but that is not what I want, I want many projects referencing the same one component located in a path above Commented Dec 13, 2021 at 17:43
  • One other thing to experiment with -- perhaps try adding an alias to the file tag, and importing via the alias, so in your .qrc: <file alias="MyComponent.qml">../../components/MyComponent.qml</file> and then for your import try simply: import "qrc:/" In theory you should be able to instantiate MyComponent via the alias you declared, without having to reference the entire path to the actual file. Should still work and run, and may just resolve the warning to boot. Commented Dec 13, 2021 at 18:53
  • regarding the first comment, clearly there is no issue when the component is "within" or "below" the root path. That was de departing point and everything was fine. At the point where there is the need of sharing a component between different projects is when the problem arises. Regarding the 2nd, already tried that (re checked with your proposal), and for this concrete case I obtain the error Unknown component. (M300). Shown as a compile time error in the .qml editor. Thanks a lot for your comments and proposal anyhow :) Commented Dec 13, 2021 at 23:10

1 Answer 1

1
+50

Adding an alias for the file in your .qrc should resolve the issue, like so:

<file alias="MyComponent.qml">../../components/MyComponent.qml</file>

and then for your import statement simply:

import "qrc:/"

The alias should resolve whatever relative path issue is causing the warning to be thrown by the designer.

Sign up to request clarification or add additional context in comments.

3 Comments

some hours need to pass for me to be able to award the bounty, but you got it. Thanks a lot, you nailed it!
Glad to help! Honestly this answer was a complete shot in the dark since I don't ever use design view... Glad it solved the issue for you though.
I was out of ammo in the dark

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.