title: PyQt QtWebKit - Return value from a Python method directly to JavaScript
body: <p><strong>EDIT:</strong></p>
  
  <p>I've found a solution here:
  <a href="https://stackoverflow.com/questions/6372336/how-do-i-correctly-return-values-from-pyqt-to-javascript">how do I correctly return values from pyqt to JavaScript?</a></p>
  
  <p>I'll post the code first:</p>
  
  <p>Python code:</p>
  
  <pre><code>class JSBridge(QObject):
      def __init__(self, parent=None):
          super(JSBridge, self).__init__(parent)
  
      @pyqtSlot(bool)
      def fromJStoPython(self, param):
          print param
          print param.toBool()
      @pyqtSlot()
      def returnValue()
          return "hello world"
  
  class another():
      ...
      view = QWebView()
      frame = view.page().mainFrame()
  
      param = "blabla"
      frame.evaluateJavaScript("printIt('" + param + "');")
      paramBool = True
      frame.evaluateJavaScript("fromPythonWithParameterBool('" + paramBool + "');")
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>function printIt(param)
  {
      alert(param);
  }
  function toPython()
  {
      jsBridgeInst.fromJStoPython(true);
  }
  // now here functions I've questions about:
  function fromPythonWithParameterBool(param)
  {
      alert(param);
  }
  function fromPythonReturnValue()
  {
      res = jsBridgeInst.returnValue();
      alert(res);
  }
  </code></pre>
  
  <p><strong>Now to my question:</strong></p>
  
  <p>The <code>printIt</code> function works fine. So the param is interpreted as a String.
  The <code>fromJStoPython</code> function also works fine. The print statement shows it's a <code>QVariant</code>.</p>
  
  <p>But the <code>fromPythonWithParameterBool</code> function does not work, because I have to convert <code>paramBool</code> into a string in order to connect it. If I do so, it's printing the string value (but I want it to be boolean). Is it possible to pass a boolean, so that in JavaScript I can work with it as a boolean? If yes, how do you do it?</p>
  
  <p>And for the <code>fromPythonReturnValue</code> function, it does not show an error, but <code>res</code> is undefined. Why?
  I was searching for that problem, but mostly the examples/tutorials show standard stuff like:</p>
  
  <pre><code>evaluateJavaScript("alert('9')";)
  </code></pre>
  
  <p>I've worked with Java and SWT, and there I could just simply return a value (as in the <code>formPythonReturnValue</code> method). There was a Browser class where you could implement your methods to call, just like JSBridge.</p>