如何使用 QT/Python 从 Javascript 调用C++函数
how to invoke C++ functions from Javascript using QT/python?
我有一个嵌入式系统,其GUI是使用html开发的。在里面,HTML,我正在编写javascript。现在,如何使用 QT 从 Javascript 调用C++函数中间件?我听说QT是从Javascript调用C++函数的最简单方法。有没有从 JAVA 脚本调用 C++ 函数的示例。我是python的新手,python提供此功能吗?例子确实对我有帮助。请通过示例解释我。此外,内部机制 - 从Javascript调用C++将很有帮助。请忽略我的蟒蛇部分,如果我听起来很奇怪。因为我对python完全陌生。我真的不知道它的力量。
假设我在 CPP 中有中间件 - 出于演示目的只有一个文件。
#include "stdio.h"
class Sample
{
private:
int net_value;
public:
Sample()
{
printf("constructor calledrn");
}
void set_value()
{
net_value = 10;
}
};
我将其编译如下。
GCC -c -fPIC 样品.cpp
GCC --shared sample.o -o libmysample.so
现在,我的HTML文件。
<html>
<head>
<script type="text/javascript">
function calculate()
{
alert('You clicked the top text');
}
function functionTwo()
{ alert('You clicked the bottom text');
}
</script>
</head>
<body>
<form action="http://136.170.195.17/cgi-bin/jordan_cgi.cgi">
<h1> Enter the First Equation </h1>
<input type=text name=val1 size=1>
X
+
<input type=text name=val2 size=1>
Y
+
<input type=text name=val3 size=1>
Z
=
<input type=text name=val4 size=1>
<h1> Enter the Second Equation </h1>
<input type=text name=val11 size=1>
X
+
<input type=text name=val12 size=1>
Y
+
<input type=text name=val13 size=1>
Z
=
<input type=text name=val14 size=1>
<h1> Enter the Third Equation </h1>
<input type=text name=va2l1 size=1>
X
+
<input type=text name=va2l2 size=1>
Y
+
<input type=text name=va2l3 size=1>
Z
=
<input type=text name=va2l4 size=1> <br>
<br>
<div><input type="submit" value="Compute!"></div>
</form>
</body>
</html>
现在,我的兴趣是从 JAVASCRIPT 函数中调用 void set_value((。
函数计算(( {
/** First instantiate Sample class and then invoke the set_value
---> Here I want to invoke set_value() -> remember the set_value is in the
.so file. **/
alert('You clicked the top text');
}
我怎样才能完成上述任务?这个例子可以进一步阐述回调部分。这样,调用 C++ 函数来注册回调和其他函数就变得很方便了。请举例说明这一点?
在javascript中使用内联C++代码,在文件cpp2js.js中提供了一个方法cpp2js(code {,callback}(。在网页中包含此文件:
<script type='text/javascript' src="cpp2js.js"></script>
JavaScript 中的内联C++函数
相关文章:
- 如何使用EM_JS从带有参数的C++调用javascript方法
- 在 v8 JavaScript 中重复调用C++是否有巨大的开销?
- 如何在 C++ 中从 V8 调用 Javascript 函数
- 从C++代码抛出错误调用 JavaScript 回调函数 - nbind
- node.js Nan:在函数C++调用 JavaScript 回调
- 如何使用 cocos creator 在 Cocos2d-X/Cocos2d-JS 中调用 javascript 函数并
- v8.从 C++ 保存和调用 JavaScript 函数
- 如何通过 MS Chakracore JavaScript 引擎调用C++函数或方法
- 我如何调用Mozilla Rhino的Javascript中的C++
- 在使用Embind的Javascript中,仅仅调用deleteLater()就足以避免内存泄漏吗
- 在WindBG断点命令中调用JavaScript函数
- 如何使用iOS上的JavaScriptCore创建从JavaScript调用的C 回调
- QT WebKit桥:使用JavaScript调用C 功能
- 我可以从JavaScript调用C 函数
- 在 Internet Explorer 中使用 Javascript 调用C++
- 如何使用 QT/Python 从 Javascript 调用C++函数
- 创建一个仅提供通过javascript调用的函数的ActiveX控件.最好的方法
- 我如何从javascript调用c++代码与NPAPI
- 如何从javascript调用c++方法
- 是否可以使用Emscripten从JavaScript调用C++函数