Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Created January 17, 2011 22:42
Show Gist options
  • Save robotlolita/783635 to your computer and use it in GitHub Desktop.
Save robotlolita/783635 to your computer and use it in GitHub Desktop.
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import *
class Everything(QObject):
@Slot(result=int)
def answer(self):
return 42
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("http://www.example.com/"))
web.show()
frame = web.page().mainFrame()
frame.addToJavaScriptWindowObject("Everything", Everything())
frame.evaluateJavaScript("alert(Everything.answer())") # It alerts 0 instead of 42
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment