Unsolved Need to signal/trigger/call/whatever from WebEngineView content...
-
...into my Qml code.
I've been reading on this and was quite surprised to find that window.postMessage doesn't exist, the Qt JavaScript bridge no longer works, and that WebChannel solutions appear to require that the page (which I do not control) must include a bunch of Qt specific JavaScript.
Is there a way for the HTML/JS content of a page viewed in a WebEngineView to signal my Qml code?
If I'm signalled I can run an eval against the page content and pull the data I need - but I can't find a way to trigger this except when a pageload completed event happens (and by this time it's too late.)
Suggestions? Thanks!
-
Nothing?
Qt has a webengine that it cannot signal itself with?
-
@VRHans said in Need to signal/trigger/call/whatever from WebEngineView content...:
I've been reading on this and was quite surprised to find that window.postMessage doesn't exist, the Qt JavaScript bridge no longer works, and that WebChannel solutions appear to require that the page (which I do not control) must include a bunch of Qt specific JavaScript.
even the HTML source isn't under your control, you can still inject JavaScript (and thus QtWebChannel) into the page.
See here for example. -
Is this considered a moderately safe (as in 'not completely fragile') approach?
In other words, I haven't evaluated the code that constitutes the JS side of QtWebChannel, so I'm wary of namespace collisions. Luckily I don't need to be triggered early on in the page's lifecycle, so I'm not likely to suffer from a race condition.
Thanks very much for the suggestion - I'll try it today :)
Hans
-
@raven-worx One question though - my webengine view is created and managed in my UI's Qml code - is this same approach available via Qml (creating a script, adding it to the document creation portion of the lifecycle, et cetera)?
I can muddy my architecture a bit if I need to do this on the C++ side, but it would be better if I did not...
-
@VRHans
The QML WebEngineView supports also profiles.
The WebEngineProfile QML Type instantiates a QQuickWebEngineProfile type.For interaction with QML elements from C++ see this.
-
@raven-worx Thx, I will get cracking on this. Much appreciated.