从 c++ 调用 qml - javascript 中的方法。范围问题
我想从 C++ 调用 qml - javascript 中的方法。 基本上我认为我已经完成了文档中所说的所有内容。 我可以调用该方法,如果它是这样的:
Rectangle {
......
Component.onCompleted:{
...........
}
function foo(arg1, arg2)
{
................
}
}
但如果我像这样把它放在一个单独的 .js 文件中,我就不能调用相同的函数:
import ../Script.js as Script
Rectangle {
.........
Component.onCompleted:{
Script.foo(arg1,arg2)
}
}
脚本已导入,一切都已导入,但我仍然有问题这表明这些论点不被认可。任何帮助将不胜感激。谢谢
I want to call a method in qml - javascript from c++.
Basically I think that I have done everything that is said in documentation.
I can call the method if it is like this:
Rectangle {
......
Component.onCompleted:{
...........
}
function foo(arg1, arg2)
{
................
}
}
But I can't call the same function if I put it like this and in a separate .js file it like this:
import ../Script.js as Script
Rectangle {
.........
Component.onCompleted:{
Script.foo(arg1,arg2)
}
}
The script is imported and everything, but I still have a problem that says that the arguments are not recognized. Any help will be appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
arg1 和 arg2 是否在矩形中的某个位置定义?
否则它应该可以工作,除了你必须用引号导入 Script.js
为了测试我使用了
Script.js
main.qml
Are arg1 and arg2 defined somewhere in your Rectangle?
Else it should work, except that you have to import the Script.js with quotation marks
For testing I used
Script.js
main.qml