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. Global js to use in more QML files (SOLVED)
Forum Updated to NodeBB v4.3 + New Features

Global js to use in more QML files (SOLVED)

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 6.1k 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
    AlterX
    wrote on last edited by
    #1

    Hi,
    i've created a .js file that contains some functions and global variable;
    I'm using it with import...as and it works well in that file. I know that a js is stateful in a QML file in fact if i import it in the other ones, the global variable are just setted to zero; well...
    my work around is just copy the Component.qml's code into the main QML (that contains the js import) and it works very well...
    I know that i must import only one time and than refer to it in the other QML file, but how???

    Thanks to all
    Gianni

    Qt Ambassador
    Real-time cooperative teams: http://www.softairrealfight.net
    Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

    https://codereview.qt-project.org/...

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

      you can use
      @
      .pragma library
      @
      and it will make your js library stateless

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

        uhm...
        i've already use it and it doesn't work for me.
        Anyway, if i use it, i must "import" in all QML file in which i need for?

        Qt Ambassador
        Real-time cooperative teams: http://www.softairrealfight.net
        Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

        https://codereview.qt-project.org/...

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          yep, you should import it everywhere you are using it, but variables declared in this js file will be same for all places where you use this js file

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AlterX
            wrote on last edited by
            #5

            Ok i'll try it...

            thank you!
            Gianni

            Qt Ambassador
            Real-time cooperative teams: http://www.softairrealfight.net
            Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

            https://codereview.qt-project.org/...

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AlterX
              wrote on last edited by
              #6

              I've added it at the top of js file...
              now i'm experiencing an error on:

              @
              if (component.status === Component.Ready)
              @

              ReferenceError: Can't find variable: Component

              Why?!

              Qt Ambassador
              Real-time cooperative teams: http://www.softairrealfight.net
              Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

              https://codereview.qt-project.org/...

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AlterX
                wrote on last edited by
                #7

                [quote author="AlterX" date="1311585310"]I've added it at the top of js file...
                now i'm experiencing an error on:

                @
                if (component.status === Component.Ready)
                @

                ReferenceError: Can't find variable: Component

                Why?![/quote]

                Ok i've seen that is a bug: when using ".pragma library" the object Component cannot exist because it is automatically bind with the import, but now only with stateful way!

                Anyway thanks

                Qt Ambassador
                Real-time cooperative teams: http://www.softairrealfight.net
                Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                https://codereview.qt-project.org/...

                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