[webkit-qt] [QtWebkitBridge] local function variables not accessible!
Ariya Hidayat
ariya.hidayat at gmail.com
Wed Sep 14 13:41:16 PDT 2011
> 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
> }
This has nothing to do at all with QtWebKit or its bridge. Please help
yourself and grab a good reference on JavaScript (I recommend
"JavaScript: The Good Parts" from Douglas Crockford).
The issue is because a variable is not accessible outside its
(function) scope. For more examples, check out
http://stackoverflow.com/questions/500431/javascript-variable-scope.
If you want to make it work, you can place your variable in the global
object, like 'window'. Depending on your use case, it may be a dirty
hack or it may be just acceptable.
Again, this is all basic JavaScript and nothing do with WebKit bridge.
Regards,
Ariya Hidayat
http://ariya.ofilabs.com
More information about the webkit-qt
mailing list