I imported existing files to my QML project. Why does my app not find the file?
(EDIT: I'm using Qt 4.8.4, just in case)
In my QML file, I have @import "../../scripts/x.js" as Test;@ and the file location is not underlined with a squiggly red line, indicating the file exists.
When I press the green play button to build and run my project, I get an error saying something like
@file:///path/to/app/myapp-build-042394-Release/qml/myapp/main.qml:2:1: Script file:///path/to/app/myapp-build-042394-Release/scripts/x.js unavailable@
, so it seems the build folders that it creates are not containing the file I added.
The same thing happens with other file types, like .ttf font files.
I added the files to my project by placing them somewhere in my project folder (e.g. file:///path/to/app/myapp/scripts/ or file:///path/to/app/myapp/fonts/), then I right-click on the project in the left, and select "Add Existing Files...", then I choose the files.
Am I doing something wrong? How do I make this work?
I just realized, if I use absolute path, I will probably not have this problem... But I'd prefer using relative paths so I can easily work on another machine and not have to find/replace each time I switch.
EDIT: Yup, I tested and it works fine with absolute paths (e.g. file:///path/to/app/myapp/scripts/x.js). But this won't work when I package my app. It will need to use a relative path so it works on any machine.
You might consider putting your .js file in a resource.
This might actually be a bug, if the relative URL is being resolved wrongly based on the base URL of the component. I assume that "file:///path/to/app/myapp-build-042394-Release/scripts/x.js" is the incorrect path, and that your project does not install the file there?
On the other hand, if that is the correct path (ie, the resolution is correct) and the project does install the file there (so it exists) but it still can't access it, then I'm not sure what could be happening.