Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Qt5WebView获取日志输出?_Qt_Webview_Qtwebkit_Console.log_Qt5.4 - Fatal编程技术网

从Qt5WebView获取日志输出?

从Qt5WebView获取日志输出?,qt,webview,qtwebkit,console.log,qt5.4,Qt,Webview,Qtwebkit,Console.log,Qt5.4,我正在尝试从Qt5WebView网页获取控制台日志输出,但我找不到如何执行该操作。 也许有人能帮我 我已经尝试启用web检查器,它应该在您右键单击web页面时显示,但我这样做时什么也没有发生。通过将环境变量QTWEBKIT_inspector_SERVER设置为1111,我在1111上设置了一个检查器端口。我可以得到一个页面,上面写着: Inspectable web views LOG TEST [http://MY_LAN_IP:8880/logtest.html] 但是,当我单击链接时

我正在尝试从Qt5WebView网页获取控制台日志输出,但我找不到如何执行该操作。 也许有人能帮我

我已经尝试启用web检查器,它应该在您右键单击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>
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

    }
}
在下面的链接中,我成功地显示了嵌入在QML WebView中的网页中的日志

在你的岗位上,你真的离目标很近了

你必须:

将运行时环境变量QTWEBKIT_INSPECTOR_SERVER设置为您想要的任意值,那么为什么不设置1111呢。 在QML文件中,导入QtWebKit.1.0 并在webview属性中添加:experimental.preferences.developerTrasEnabled:true 然后,启动应用程序时,必须具有以下输出跟踪:

Inspector server started successfully. Try pointing a WebKit browser to http://127.0.0.1:1111
要调试您的页面,请打开您最喜爱的web浏览器并转到,即可完成

因此,界面已更改,在旧的QtWebKit中,您必须右键单击web视图以调试页面,现在您必须通过web浏览器连接到服务器