简体   繁体   English

使用结构/对象参数从QT调用JavaScript回调

[英]Invoke JavaScript callback from QT with structure/object argument

I am using QT 5.5 version. 我正在使用QT 5.5版本。

I need to invoke javascript callback function from QT plugin with Structure/Object as argument. 我需要从QT插件以Structure / Object作为参数调用javascript回调函数。 I could not modify HTML Application since it is not in our scope. 我无法修改HTML应用程序,因为它不在我们的范围内。

HTML application code snippet HTML应用程序代码段

var obj1 = document.getElementById('obj1_id'); //QT plugin object 1
var obj2 = document.getElementById('obj2_id'); //QT plugin object 2
obj2.init(obj1,callback); //QT API
function callback(arg1)
{
if ( obj1 === arg1){
// SUCCESS
else
// FAILURE
}

QT plugin code snippet QT插件代码段

class::init(QWebElement obj, QString callback)
{
    //need to Invoke callback with obj argument
}

Can any one help me on this? 谁可以帮我这个事?

Using Qt Signals and Slots - 使用Qt信号和插槽-

In your javascript function - 在您的javascript函数中-

add the following line - 添加以下行-

myoperation.alert_script_signal.connect(callback); myoperation.alert_script_signal.connect(回调);

In the Qt framework based C++ class - constructor, add the following line - 在基于Qt框架的C ++类-构造函数中,添加以下行-

Register your Javascript callback -- 注册您的Javascript回调-

view->page()->mainFrame()->addToJavaScriptWindowObject("myoperation", this); view-> page()-> mainFrame()-> addToJavaScriptWindowObject(“ myoperation”,this);

// now invoke the callback from some method in that Qt class. //现在从该Qt类中的某个方法调用回调。

emit alert_script_signal(); 发出alert_script_signal();

You need to understand one thing that QtWebkit is the platform here. 您需要了解QtWebkit是此处平台的一件事。 So, basically, the html, javascript is running on the Qt Webkit. 因此,基本上,html,javascript在Qt Webkit上运行。

I have some examples - http://www.tune2wizard.com/linux-qt-callback-from-c-to-the-javascript-function/ 我有一些示例-http: //www.tune2wizard.com/linux-qt-callback-from-c-to-the-javascript-function/

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

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