QtWebKit: Failed to addToJavaScriptWindowObject when two QWebView binding to one obj

StackOverflow https://stackoverflow.com/questions/17894215

  •  04-06-2022
  •  | 
  •  

Вопрос

I have two QWebView instances(webView1 and webView2), both of them have a same statement like this:

webView->page()->mainFrame()->addToJavaScriptWindowObject("JSCallable", parent);

which parent refers to a same instance that have public slots for JS to invoke(i.e. both webView1 and webView2 will call the same method of the same instance), and I do call this statement whenever the webView(webView1 and webView2) load a new URL;


Now the problem is: only one webView can call the method of parent successfully while the other cannot.

I wonder whether it is possible to binding two webView to one obj for the purpose that the JavaScript in different pages can call a same method of a QObject.

Any one would help? I will thank you in advance.


Qt 4.8.4 / VS2010 with Windows 7

Это было полезно?

Решение

After trial of several times, i figured it out that it was Possible to do stuff above.

I think this problem should be closed.

EDIT:

As mentioned in the comment that i should post the answer, so just modify the answer:

Yes it is Possible to register two webView to one obj, you just do what you do when you have only one webView, I did it wrong somewhere in the first place and worked it out later.

(Post it in case someone else encounter the same situation)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top