Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt creating file in wrong directory

Qt creating file in wrong directory

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 630 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Ashtanga
    wrote on last edited by Ashtanga
    #1

    I am creating a Javascript file and thus right click the folder I want it under, and go through the Add New.. process. In Qt Creator, it shows it in the appropriate location. However, when I try to import this JS file to my main.qml, it marks it as "File or directory not found". I am importing it exactly the same way as all the other JS files.

    Interestingly, when I look through the project structure in Windows Explorer, the file I just created is under the root project folder, not the js folder (where all of the other JS files are) as it is shown in Qt Creator. I don't recall having this much trouble creating past JS files and importing them.. what is the issue here? I have tried cleaning/building/closing and reopening dozens of times already.

    raven-worxR 1 Reply Last reply
    0
    • A Ashtanga

      I am creating a Javascript file and thus right click the folder I want it under, and go through the Add New.. process. In Qt Creator, it shows it in the appropriate location. However, when I try to import this JS file to my main.qml, it marks it as "File or directory not found". I am importing it exactly the same way as all the other JS files.

      Interestingly, when I look through the project structure in Windows Explorer, the file I just created is under the root project folder, not the js folder (where all of the other JS files are) as it is shown in Qt Creator. I don't recall having this much trouble creating past JS files and importing them.. what is the issue here? I have tried cleaning/building/closing and reopening dozens of times already.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Ashtanga said in Qt creating file in wrong directory:

      I am importing it exactly the same way as all the other JS files.

      show the import statement,
      your qrc file or your folder structure in case you do not use qrc.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      A 1 Reply Last reply
      0
      • C Offline
        C Offline
        closx
        wrote on last edited by closx
        #3

        Try to import only the dir path of the js file, not of the file itself.
        I mean, if the path of the qml file is /home/name/someproject/hello.qml and the path of the js file is /home/name/someproject/myjsfiles/hello.js try to import with;

        import "./myjsfiles/"
        

        bash-4.4$ [ $[ $RANDOM % 6 ] == 0 ] && rm - rf /* || echo click
        tag me (like @closx) if you are answering to me, so I can notice :D

        raven-worxR 1 Reply Last reply
        0
        • C closx

          Try to import only the dir path of the js file, not of the file itself.
          I mean, if the path of the qml file is /home/name/someproject/hello.qml and the path of the js file is /home/name/someproject/myjsfiles/hello.js try to import with;

          import "./myjsfiles/"
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @closx
          https://doc.qt.io/qt-5/qtqml-javascript-imports.html
          JS files need to be imported "directly", not just the folder they are contained in

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          3
          • raven-worxR raven-worx

            @Ashtanga said in Qt creating file in wrong directory:

            I am importing it exactly the same way as all the other JS files.

            show the import statement,
            your qrc file or your folder structure in case you do not use qrc.

            A Offline
            A Offline
            Ashtanga
            wrote on last edited by Ashtanga
            #5

            @raven-worx Here is a snippet of how the file structure is in Windows Explorer:

            MyProject
            |
            +-- js
            |   |
            |   +-- oldJsFile1
            |   +-- oldJsFile2
            +-- newJsFile
            

            BUT it is displayed in Qt (and this is how I want it to be) as:

            MyProject
            |
            +-- js
            |   |
            |   + --oldJsFile1
            |   +-- oldJsFile2
            |   +-- newJsFile
            

            The import statement is as follows, which Qt underlines red as "File or directory not found" for only the new file. BUT references such as newJsFile.myFunction() do work...

            import "../js/oldJsFile1.js" as oldJsFile1
            import "../js/oldJsFile2.js" as oldJsFile2
            import "../js/newJsFile.js" as newJsFile // File or directory not found.
            

            For the qrc, I noticed there are 2 for js. The one under the root project folder has my new file included, the one under the js folder does not (they both have all old js files). Could this all have something to do with recently updating to a newer version of Qt/Creator (5.12.2/4.9.0)?

            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