1
我想从Qt 5 WebView网页获取控制台日志输出,但我无法找到如何去做。 也许有些你可以帮助我吗?从Qt 5 WebView获取日志输出?
我试图启用当您右键单击网页时显示的Web检查器,但是当我这样做时没有任何反应。我已经通过了环境变量QTWEBKIT_INSPECTOR_SERVER设置为1111设立督察端口(在1111),我能够得到一个网页,有这个就可以了:
Inspectable web views
LOG TEST [http://MY_LAN_IP:8880/logtest.html]
但是当我点击我得到这个链接错误:
WebSocket connection to 'ws://localhost:1111/devtools/page/1' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received
inspector.js:341 Event {clipboardData: undefined, path: NodeList[0], cancelBubble: false, returnValue: true, srcElement: WebSocket…}
View.js:363 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
为了演示我有一个看起来像这样的本地Web服务器上的网页:
<!DOCTYPE html>
<html>
<head>
<title>LOG TEST</title>
</head>
<body>
<h1>Logging to console...</h1>
<script>
setInterval(function() {
console.log("This is a log message");
console.error("This is an error message");
}, 1000);
</script>
</body>
</html>
的QML文件看起来是这样的:
import QtQuick 2.2
import QtQuick.Window 2.1
import QtWebKit 3.0
import QtWebKit.experimental 1.0
Window {
visible: true
width: 360
height: 360
WebView {
url: "http://MY_LAN_IP:8880/logtest.html"
anchors.fill: parent
experimental.preferences.developerExtrasEnabled: true
experimental.preferences.navigatorQtObjectEnabled: false
}
}