Hi all,

I have a strange problem, that I can reproduce but don't understand. Yet.

I have a dialog, with two webviews (webview1, and webview2) and two spinBoxes (firstSpinBox and secondSpinBox)
I'd like webview1 to act (with javascript) on firstSpinBox and webview2 on secondSpinBox.

Here is some code to illustrate it:

Qt Code:
  1. MyDlg::MyDlg(QWidget *parent)
  2. :QDialog(parent)
  3. {
  4. setupUi(this);
  5.  
  6. QWebFrame *first_frame = webview1->page()->mainFrame();
  7. QWebFrame *second_frame = webview2->page()->mainFrame();
  8.  
  9. connect(first_frame, SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJavaScriptObject()));
  10. connect(second_frame, SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJavaScriptObject()));
  11.  
  12. webview1->setUrl(QUrl("qrc:///assets/html/first.html"));
  13. webview2->setUrl(QUrl("qrc:///assets/html/second.html"));
  14. }
  15.  
  16. void MyDlg::addJavaScriptObject()
  17. {
  18. QWebFrame *first_frame = webview1->page()->mainFrame();
  19. QWebFrame *second_frame = webview2->page()->mainFrame();
  20.  
  21. first_frame->addToJavaScriptWindowObject("first", firstSpinBox);
  22. second_frame->addToJavaScriptWindowObject("second", secondSpinBox);
  23. }
To copy to clipboard, switch view to plain text mode 

Now what happens is this:

Only webview1 (that is first_frame) recognizes firstSpinBox in its javascript.
webview2 (second_frame) doesn't recognize secondSpinBox.

The strange thing, or maybe the explanation, is if I load webview2 first, that is, if I do:

Qt Code:
  1. // Invert loading order
  2. webview2->setUrl(QUrl("qrc:///assets/html/second.html"));
  3. webview1->setUrl(QUrl("qrc:///assets/html/first.html"));
To copy to clipboard, switch view to plain text mode 

In that case, webview2 javascript recognizes secondSpinBox, but, webview1 doesn't recognize firstSpinBox.

I thought the two webviews were separate and don't share anything, but it looks like the event "javaScriptWindowObjectCleared())" acts on the whole app?

Thanks a lot in advance