It's not easy. Here is a workaround, it's imperfect but practical enough.
Create a subclass of QObject
, e.g. Notifier
. This will be your bridge from the web world to the native world. Whatever change you want to implement if a checkbox is checked should be placed here directly or you can forward it further down the chain via the signal/slot mechanism.
Inject an instance of this Notifier
object into your web page using addToJavaScriptWindowObject. It will be attached to the global window
object. Now, use DOM's addEventListener to add a new listener to the checkbox, the listener does nothing but to invoke the bridge's callback, e.g. window.notifier.doSomething()
. This listener tweak can be carried out by executing a small JavaScript code using evaluateJavaScript.
This trick works because QtWebKit internal bridge understands a QObject instance (though introspection) and make its properties and slots accessible from the JavaScript world.