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. Best practice: Integrate .js file to a project
Forum Updated to NodeBB v4.3 + New Features

Best practice: Integrate .js file to a project

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.9k 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.
  • I Offline
    I Offline
    Iqscope
    wrote on last edited by
    #1

    Hi,

    the question is, how to properly add a .js file to my project.
    Currently, I have created a qrc file and add the .js file to it.
    Now, I can reference to it with an import statement like this:
    @import "qrc:/helper.js" as Helper@
    This works, but the Qt Creator has marked this as an error with a red underline.

    If I use loose .js files and reference with
    @import "helper.js" as Helper@

    this has to be deployed as a loose file, too. So, anyone can simply manipulate it.

    So, what is the best way? Perhaps there are much more ways...

    1 Reply Last reply
    0
    • D Offline
      D Offline
      daliusd
      wrote on last edited by
      #2

      You make wrong assumption that file in qrc can't be read or manipulated. I just did that with one core N9 app last month as I have tried to figure out what I should pass to it.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Iqscope
        wrote on last edited by
        #3

        Ok, that's right.
        But for a normal user, it is harder to access a qrc file than a plain file.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          matti-
          wrote on last edited by
          #4

          At least when the js/qml files are in the same qrc file, you can adress the .js files like so from QML:

          @
          import "helper.js" as Helper
          @

          even when theyre inside the qrc. This works with QtQuick2 at least.

          • M

          Author of <a href="http://mmark.777-team.org/">MMark13</a>

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Iqscope
            wrote on last edited by
            #5

            this doesn't work for me.

            The program didn't find the file.
            Perhaps this is because of my mac system.
            But in Qt Creator this is an error, too.

            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