Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. I imported existing files to my QML project. Why does my app not find the file?

I imported existing files to my QML project. Why does my app not find the file?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    trusktr
    wrote on last edited by
    #1

    (EDIT: I'm using Qt 4.8.4, just in case)

    I placed a javascript file inside my project and followed the instructions at http://qt-project.org/doc/qt-5.0/qtqml/qtqml-javascript-imports.html to import my file into QML.

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      trusktr
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        You might consider putting your .js file in a resource.

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisadams
          wrote on last edited by
          #4

          Hi,

          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.

          Cheers,
          Chris.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved