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

Stephen Collyer scollyer at netspinner.co.uk
Mon May 24 16:31:47 CEST 2010


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

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100524/1076a411/attachment.html 


More information about the Qt-interest-old mailing list