Problems importing another JavaScript library into QML

  • I am working in Cascades/QML and am using JavaScript for handling my application logic. I have this external javascript library (a .js file) located inside the assets, so I do something like this

    @import "libname.js" as Library@

    and the library was designed such that it defined a global object like :

    @LibGlobalObject = function (param) {
    //Some action

    and then it keeps adding methods by doing something like

    @GoodLib.prototype.methodOne = function(param) { };
    GoodLib.prototype.methodTwo = function(param) { };@

    and it says it can be used by doing something like :

    @(new GoodLib(someParam)).methodOne(new GoodLib(someParam));
    (new GoodLib(someParam)).methodTwo(new GoodLib(someParam));@

    so I thought of doing something like

    @(new Library.GoodLib(someParam)).methodOne(new Library.GoodLib(someParam));
    (new Library.GoodLib(someParam)).methodOne(new Library.GoodLib(someParam));@

    in my QML but it doesn't work.

    Can anyone tell me what it is that I'm doing wrong here ?

  • What is GoodLib?

  • Sorry I seem to have made a mistake in posting here. It should be

    @GoodLib = function (param) {
    //Some action

    and GoodLib is the name of the global object that the library creates so that I can do calls like :

    @new GoodLib(someParam)@

  • OK. Your code looks good. What does not work for you? Do you get any error message?

    The only thing that you must be aware about: each import creates independent space (or at least that's my impression). It is better to use properties for keeping global state.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.