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. Import a plugin inside a javascript file
Forum Update on Monday, May 27th 2025

Import a plugin inside a javascript file

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 2.0k 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.
  • I Offline
    I Offline
    Iqscope
    wrote on 19 Jan 2013, 13:30 last edited by
    #1

    Hi,
    I've made a plugin wich I want to use in a javascript file.
    So I want to do something like this:

    test.js:
    @
    .pragma library
    import MyPlugin 1.0 // <- No way in js file?

    function test() {
    return MyPlugin.DoSomething();
    }
    @

    Currently, I can't find a way to use my plugin inside the script file...
    I think, Qt.include only can handle javascript files.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      daliusd
      wrote on 20 Jan 2013, 11:12 last edited by
      #2

      I believe if you will import your plugin and javascript later in QML file you will be able to access plugin in javascript file. I personally have not seen a way to import plugin in javascript file directly.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Iqscope
        wrote on 20 Jan 2013, 20:42 last edited by
        #3

        Good idea but it doesn't work. I get an error, that the plugin objects could not be found.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          daliusd
          wrote on 20 Jan 2013, 20:59 last edited by
          #4

          OK. Maybe it is not working with plugins in this way. But I can assure you that it works with custom objects (I use that in several apps). E.g. if we have Person object from here: http://doc.qt.digia.com/qt/qml-extending.html

          @Person {
          id: personA
          }@

          You can use personA.someMethod() in *.js files. I hope that helps.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            chrisadams
            wrote on 20 Jan 2013, 23:52 last edited by
            #5

            Hi,

            Please see http://doc-snapshot.qt-project.org/5.0/qtqml/qtqml-javascript-imports.html#imports-within-javascript-resources for the relevant documentation. Note that imports from within JavaScript resources is only supported in QML2, not QML1.x.

            Cheers,
            Chris.

            1 Reply Last reply
            0
            • I Offline
              I Offline
              Iqscope
              wrote on 21 Jan 2013, 19:23 last edited by
              #6

              You are my man, thank you!

              That works perfectly!

              Here my solution:
              @
              .import MyPlugin 1.0 as My
              My.ClassName.TestFunction();
              @

              1 Reply Last reply
              0

              1/6

              19 Jan 2013, 13:30

              • Login

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