[英]How can I call another QtScript .js file from one QtScript .js file
now I can use QScriptEngine to load and execute a test.js file. 现在,我可以使用QScriptEngine加载并执行一个test.js文件。 In one of the function of that test.js I'd like to call another function located in another .js file.
在该test.js的函数中,我想调用另一个.js文件中的另一个函数。 How do I do this?
我该怎么做呢?
To load QTScript Code from multiple files you need to load all those file using QScriptEngine.evaluate(). 要从多个文件加载QTScript代码,您需要使用QScriptEngine.evaluate()加载所有这些文件。 Then those methods will be available to all the JS environment according to the rules of JS.
然后,这些方法将根据JS规则对所有JS环境可用。 ie: you will be able access global methods directly.
即:您将可以直接访问全局方法。
But if you are working on a big project, I would strongly suggest you use some common JS implementation in QT. 但是,如果您正在从事大型项目,我强烈建议您在QT中使用一些常见的JS实现。 I have worked on a fairly large project on QTScript and it used work great for us.
我已经在QTScript上进行了一个相当大的项目,并且它对我们非常有用。 Here is a link which goes into little detail of how you can implement that in QT.
这里的链接很少介绍如何在QT中实施该链接 。
Add both js files in your program. 在程序中添加两个js文件。 The order of adding those is:
添加这些的顺序是:
another.js
file another.js
文件 test.js
file test.js
文件 Then you can call the function directly if you defined it in global scope(window scope), like : 然后,如果您在全局范围(窗口范围)中定义了函数,则可以直接调用该函数,例如:
In another js : 在另一个js中:
function myFunc() { /* your code here */ }
In test.js: 在test.js中:
myFunc();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.