Qt5 QML QtWebKit 3.0 NO javaScriptWindowObjects ?
-
Hi i recently changed from qt4 to qt5. Now i wonder if this functionality is implemented in the new qtwebkit 3.0? I looked at the API [http://doc-snapshot.qt-project.org/5.0/qtwebkit/qml-qtwebkit3-webview.html] and there is an incredible decrease of available properties especially the one i am searching for.
Any ideas how i can add new javascript objects to the webview in qtwebkit 3.0?
regards
-
Currently it requires using "QtWebKit.experimental 1.0" and there is no javaScriptWindowObjects. Communicating needs to be handled using method experimental.postMessage and signal experimental.onMessageReceived.
There seems to be also evaluateJavaScript method and property named userScripts. -
Thx, for the quick answer.
The earliest possibly to check this out is Thursday to give feedback. May i ask you where you get this information? I don't wanna come here with every stupid question, if i can simply read about that.regards
-
Just for the record, if someone has the need for it.
@import QtQuick 2.0
import QtWebKit 3.0
import QtWebKit.experimental 1.0Rectangle {
width: 1024
height: 768WebView{
url: "http://localhost"
anchors.fill: parentexperimental.preferences.navigatorQtObjectEnabled: true experimental.onMessageReceived: { console.debug("get msg from javascript") experimental.postMessage("HELLO") }
} // webview
} // rectanlge@altered it to get it through the forum parser :)
@<html>
<body>
<h1>It just works!</h1><p>Play with me...</p>
<button o n c l c i k="nativecall();">test</button>
<div id="out"></div><s r c p i t t p y e="t x e t / j a v s a c i r p t ">
function nativecall(){
console.log("will try native call");
var elem = document.getElementById("out"). inner H t M l ="clicked";
navigator.qt.postMessage('this is a js call');
}function jsCall(message){ var elem = document.getElementById("out"). inner H t M l ="and the other way around " + message; } navigator.qt.onmessage = function(ev) { jsCall(ev.data); }
</ script >
</body>
</html>@ -
The cpp to js bridge example here was very useful. thanks.