繁体   English   中英

如何使用QT / python从Javascript调用C ++函数?

[英]how to invoke C++ functions from Javascript using QT/python?

我有一个嵌入式系统,其GUI使用html开发。 在HTML里面,我正在编写JavaScript。 现在,如何使用QT从Java调用C ++函数-中间件? 我听说QT是从Javascript调用C ++函数的最简单方法。 有没有示例可以从JAVA SCRIPT调用C ++函数。 我对python完全陌生,python是否提供此功能? 例子对我有帮助。 请通过示例向我解释。 另外,内部机制-从Java脚本调用C ++将很有帮助。 如果我听起来很奇怪,请忽略我的python部分。 因为我对python完全陌生。 我真的没有力量。

假设,我在CPP中拥有中间件-出于演示目的,只有一个文件。

#include "stdio.h"

class Sample
{

 private:

   int net_value;


public:


  Sample()
  {

    printf("constructor called\r\n");

  }



 void set_value()
  {
    net_value = 10;

  }


};

我将其编译如下。

gcc -c -fPIC sample.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()。

函数calculate(){

  /** 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 ++函数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM