Getting sender (QWebView) of javaScriptWindowObjectCleared signal



  • Hi
    I had a single QWebView. Upon the creation I do

    connect(webGUI->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()));
    

    to be able to call a native function from JavaScript.
    The slot:

    void QTGUI_MainWindow::populateJavaScriptWindowObject()
    {
      webGUI->page()->mainFrame()->addToJavaScriptWindowObject("NativeBridge", this);
    }
    

    When I was having only one WebView that worked perfectly.

    I now create additional QWebViews as needed at run-time.
    The connect upon their creation stays the same.
    However, the slot to re-add the object needs to know the QWebView the JavaScript signal did come from.
    I actually have a map where I store all the QWebView * for every one created. What I dont have is the sender from which the javaScriptWindowObjectCleared has been sent.
    How can I get that?
    Thanks



  • Got it solved :-)

      QWebFrame * webGUIframe = qobject_cast<QWebFrame *>(sender());
      QWebView * webGUI = (QWebView*)(webGUIframe->parent())->parent();
      webGUI->page()->mainFrame()->addToJavaScriptWindowObject("NativeBridge", this);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.