[Qt-interest] QWebFrame::addToJavaScriptWindowObject() - javascript functions fail to run

tang ke tangk at lemote.com
Wed Jul 14 08:54:58 CEST 2010


于 2010年05月24日 22:31, Stephen Collyer 写道:
> I'm trying to connect a signal emitted in a QWebView subclass to
> a javascript function in a displayed HTML page.
>
> 1. I have the following code to connect the signal to the JS function:
>
> ParagraphHtml::ParagraphHtml(...)
> : QWebView(parent)
> {
> QWebFrame *frame = page()->mainFrame();
> connect(frame, SIGNAL( javaScriptWindowObjectCleared() ),
> this, SLOT( add_object_to_javascript() ));
> }
>
> void ParagraphHtml::add_object_to_javascript()
> {
> QWebFrame *frame = page()->mainFrame();
> frame->addToJavaScriptWindowObject("paragraph_object", this);
> frame->evaluateJavaScript("paragraph_object.show_paragraph_labels.connect(show_labels);");
> frame->evaluateJavaScript("paragraph_object.hide_paragraph_labels.connect(hide_labels);");
> }
>
when the HTML is writed as such:
<script type="text/Javascript">
paragraph_object.value = "hello world"
</script>

how to write the code at paragraph_object class.

use the slots function can resolve the paragraph_object.play() function .
> I have verified that the add_object_to_javascript slot is being called.
> It is supposed to make the current object visible to the JS engine, and
> to connect the show/hide_paragraph_labels signals to the corresponding
> JS functions show_labels and hide_labels.
>
> 2. I have verified via a temporary onload in the HTML that the
> show_labels function
> can be called (at the moment it merely displays an alert box).
>
> 3. When the show/hide_paragraph_labels signals are emitted, the supposedly
> connected JS functions are not run.
>
> I'm stumped as to how to debug this, at this point.
>
> -- 
> Stephen Collyer
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tangk.vcf
Type: text/x-vcard
Size: 487 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100714/bb4f0546/attachment.vcf 


More information about the Qt-interest-old mailing list