1

I have a QGIS plugin which contains a qtwebview and Javascript communication between the page and the plugin.

It is working perfectly with QGIS 2.2 but not with 2.4 (both QGIS versions share the same plugin directory),

The javascript side never gets called with evaluateJavaScript() and the python side never gets invoked from Javascript either.

What could explain that it is working in 2.2 but not in 2.4?

def on_loadFinished(self):

...


def init_Clicked(self,iface):
    self.ui.webViewResult.page().mainFrame().addToJavaScriptWindowObject("QGISInterface", self.moTAZJsInterface)
    self.ui.webViewResult.loadFinished.connect(self.on_loadFinished)
    self.ui.webViewResult.load( QUrl(config["TAZ_URL_INTERFACE"]))
    self.ui.webViewResult.show();
3
  • Ok, I found a solution. Moving the call to addToJavaScriptWindowObject () within on_loadfinished() solved the problem for 2.4 . In 2.2, I was calling addToJavaScriptWindowObject() before loading the page ... following this post: stackoverflow.com/questions/14208166/…
    – Vincent D.
    Aug 8, 2014 at 18:14
  • Perhaps you can update your code and post it as an answer?
    – Joseph
    Aug 11, 2014 at 9:38
  • remember to reload/reinject your object if the QWebView page is reloaded Aug 27, 2014 at 10:52

1 Answer 1

1

So this is the answer. I guess this can be cause by the introduction of multithreading in 2.4.

def on_loadFinished(self):

  self.ui.webViewResult.page().mainFrame().addToJavaScriptWindowObject("QGISInterface",  self.moTAZJsInterface)


def init_Clicked(self,iface):

  self.ui.webViewResult.loadFinished.connect(self.on_loadFinished)
  self.ui.webViewResult.load( QUrl(config["TAZ_URL_INTERFACE"]))
  self.ui.webViewResult.show();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.