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

rustyBucketBay
  • 4,320
  • 3
  • 17
  • 47
  • 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? – dabbler Dec 13 '21 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 – rustyBucketBay Dec 13 '21 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 – rustyBucketBay Dec 13 '21 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: `../../components/MyComponent.qml` 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. – dabbler Dec 13 '21 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 :) – rustyBucketBay Dec 13 '21 at 23:10
  • Did you actually already try that? You'll need to add the alias line to the resource file and the component will be recognized just fine. You shouldn't get that error if you have the alias, I use alias all the time in QML resources specifically so I don't have to bother with relative paths in my QML files. – dabbler Dec 13 '21 at 23:18
  • restarting qtcreator removed that. Actually the `import "qrc:/"` was what was working when the component was within the root path, and no path handling was needed. Think that neither the alias thing. I find a awkard that with direct paths or qrc paths there are this issues as it the most intuitive thing to try, however this seems to work and the warning is gone. Thank you very much. Please add an answer and the bounty is yours. – rustyBucketBay Dec 13 '21 at 23:33

1 Answers1

1

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.

dabbler
  • 404
  • 3
  • 8