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

sunny shah sunny.cpp at gmail.com
Wed Sep 14 14:43:15 PDT 2011


Hi Ariya & Alexis,

Thanks for pointing this out,

I mis-understood the problem

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.

I am working in a project where requirement is that from JS we are calling
slots with success and failure JS functions as arguements, if slots gets
success in functionality, it calls success JS function and, if it gets
failure in functionality it calls failure JS function.

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); } );
}

Thanks for understanding this issue, Any solution to this problem?

Note, We can not change the JS code, as lots and lots of JS code is already
written.

Thanks,
 Sunny

On Thu, Sep 15, 2011 at 2:15 AM, Alexis Menard
<alexis.menard at openbossa.org>wrote:

>
> On Sep 14, 2011, at 5:33 PM, sunny shah wrote:
>
> > Hi,
> >
> > Suppose, below is my JS Code in html file
> >
> > function analyzeImages() {
> >   var strHello = "Hello World"
> >   imageAnalyzer.startAnalysis();
> > }
> >
> > Now, Here is a startAnalyzer slot code in C++
> > void ImageAnalyzer::startAnalysis() {
> > // Below code works ( Gives message box )
> > ((MainWin*)parent())->page()->mainFrame()->evaluateJavaScript("alert('Qt
> is good'); ");
> > // Now below line does not work.
> >
> ((MainWin*)parent())->page()->mainFrame()->evaluateJavaScript("alert(strHello);
> ");
> >  // do something
> > }
> >
> > 1). Any idea, how to make it work?
>
> Just put the variable in the global object, i.e. a global variable.
>
> > 2). If it is not supported by QtWebkitBridge, then can you please tell me
> what was the reason behind it?
>
> How do you expect the C++ slot to know about the JS context of the fct?
> Magic?
>
> > 3). It is very important for us to make this work, can you please tell me
> how to do this?
> >
> > Thanks,
> >  Sunny.
> > _______________________________________________
> > webkit-qt mailing list
> > webkit-qt at lists.webkit.org
> > http://lists.webkit.org/mailman/listinfo.cgi/webkit-qt
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-qt/attachments/20110915/acec967c/attachment.html>


More information about the webkit-qt mailing list