Hi all:
Some time ago I developed a browser using WebkitGTK, and added some extra javascript objects to implement a framework I needed for a project.
Now I need to rewrite this browser using QtWebKit. I've been successful in calling C++ methods from JavaScript, but now I need to register a JavaScript callback, and be able to call it from C++. In the original system I built a C function which received an object as parameter (using JSValueToObject to convert the value received by the function to an object). That object was the JavaScript function to be called as callback. An example: this Javascript code registers the JavaScript callback called cb_function:
bool cb_function(param1, param2) {
alert("This is the callback, called with "+param1);
}
my_c_class.set_callback(cb_function);
bool cb_function(param1, param2) {
alert("This is the callback, called with "+param1);
}
my_c_class.set_callback(cb_function);
To copy to clipboard, switch view to plain text mode
Here, I define the cb_function callback, and send it as a parameter to the underlying framework. Then, in C, I used JSObjectCallAsFunction() to call the JavaScript function whenever I needed, sending to it some parameters.
What I need to know is how to do this with QtWebKit instead. I presume that the first part needs to use a Q_INVOKABLE method (called, in this case, set_callback) which receives the function. The problem is which type to use. If I put a String, I receive a text transcript of the function itself, not an object that I can call. Should it need to be a QVariant or a QObject?
And now the second part: how can I call from C++ that function I received?
Thanks!!!
Bookmarks