[Interest] Event from Javascript to WebEngineView

Kai Koehne Kai.Koehne at qt.io
Fri Oct 28 09:46:22 CEST 2016



> -----Original Message-----
> From: Interest [mailto:interest-bounces+kai.koehne=qt.io at qt-project.org]
> On Behalf Of Jani Tykka
> Sent: Friday, October 28, 2016 9:03 AM
> To: interest at qt-project.org Interest <interest at qt-project.org>
> Subject: [Interest] Event from Javascript to WebEngineView
> 
> Hi,
> 
> How I can get events from JS to my QML WebEngineView? 
>
> I'm trying
> something like:
> 
> in WebEngineView.LoadSucceededStatus
> {
>    var js = "window.addEventListener( \"message\", function(event) {
> console.log( \"RECEIVED EVENT Result: \" ); } )"
>    webViewLoader.item.runJavaScript( js, function(result) { console.log(
> "Result: " + result); } ) }
> 
> This works, but I'd like to be able to declare JS function as a param not the
> hardcoded string. 

The arguably best way for HTML5/Qt communciation is using a WebChannel. 
You can use e.g. the WebEngineView.userScripts property to 'inject' JS code
that then sets up the web channel and hooks into DOM handlers.

Regards

Kai


More information about the Interest mailing list