Chris Crook
Chris Crook

Reputation: 343

Access python function from javascript in QWebView

I am writing a Python/PyQt4 application that generates and displays a page in a QWebView widget. The page includes javascript code that I would like to be able to call functions returning data from the python application.

So far I can call functions that do not return data (using the pyqtSlot decorator), and call functions that do take parameters by exposing them as properties (using the pyqtProperty decorator). What I haven't worked out how to do is to call a python function with parameters, that returns data.

The question 9615194 explains how to do this from C++, but I cannot see how to transfer this to PyQt4.

Upvotes: 0

Views: 750

Answers (1)

evadeflow
evadeflow

Reputation: 4944

I suspect you're not using the result= keyword to specify the return value in your pyqtSlot decorator?

@pyqtSlot(str, result=str)
def echo(self, phrase):
    return self.parent().echo(phrase)

I ran afoul of this myself recently. No errors are generated if you omit result=, the method just silently returns nothing. Pretty maddening 'til I figured it out. See my answer to this question for a worked example.

Upvotes: 1

Related Questions