[webkit-qt] [QtWebkitBridge] local function variables not accessible!

Ariya Hidayat ariya.hidayat at gmail.com
Wed Sep 14 15:00:26 PDT 2011

> I found that, the actual problem is QtWebkitBridge does not provide a way
> to, passing JS function to C++ slot and calling JS function from invoked C++
> slot.

You can't do that at all because the bridge relies on QVariant and
conversion to/from QVariant is lossy. Since QVariant is just a
container for different opaque data type, it does not understand
function and closure from the JS world.

This problem might be solved in the future, iff the bridge exposes the
object as e.g. QScriptValue like in QtScript module.

> Now, as there is no functionality to call JS functions from the Invoked
> Slot, we implemented a hack that is,
> 1). While calling Qt Slot, QtWebKitBridge converts JS function to QString
> datatype.
> 2). we use QWebFrame::EvaluateJavaScript and connect success and failure JS
> functions to two signals of the current object.
> 3). Now, If we get success, we emit the success and failure signals and
> connected JS functions gets called.
> Now this hack does not work, if call to my slot is done with code like
> below,
> function analyzeImages() {
>   var strHello = "Hello World"
>  // Below is a call to slot
>   imageAnalyzer.startAnalysis( function () { alert(strHello); } );
> }

Your hack breaks exactly when it involves closures, that's because the
string representation of the (callback) function does not understand

I am afraid there is no clean solution for your problem.

Ariya Hidayat, Passionate Technologist

More information about the webkit-qt mailing list