Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    QML and Qt Quick
    3
    4
    2002
    Loading More Posts
    • 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
      trusktr last edited by

      (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 Reply Quote 0
      • T
        trusktr last edited by

        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 Reply Quote 0
        • M
          mlong last edited by

          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 Reply Quote 0
          • C
            chrisadams last edited by

            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 Reply Quote 0
            • First post
              Last post