Import a plugin inside a javascript file
-
wrote on 19 Jan 2013, 13:30 last edited by
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. -
wrote on 20 Jan 2013, 11:12 last edited by
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.
-
wrote on 20 Jan 2013, 20:42 last edited by
Good idea but it doesn't work. I get an error, that the plugin objects could not be found.
-
wrote on 20 Jan 2013, 20:59 last edited by
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.
-
wrote on 20 Jan 2013, 23:52 last edited by
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. -
wrote on 21 Jan 2013, 19:23 last edited by
You are my man, thank you!
That works perfectly!
Here my solution:
@
.import MyPlugin 1.0 as My
My.ClassName.TestFunction();
@
1/6