Qt内置浏览器引擎WebEngine调试和分析方法

问题背景

H5和JS代码写好了,在浏览器里调试也一切OK,然后嵌入到Qt中,发现各种问题,这时候,如何在Qt框架下调试Web的代码呢?

调试方法

在Qt帮助文档中,搜索Qt WebEngine Debugging and Profiling,重点关注Qt WebEngine Developer Tools

The Qt WebEngine module provides web developer tools that make it easy to inspect and debug layout and performance issues of any web content.
The developer tools are accessed as a local web page using a Chromium or Qt WebEngine based browser, such as the Chrome browser.
To activate the developer tools, start an application that uses Qt WebEngine with the command-line arguments:
–remote-debugging-port=<port_number>
Where <port_number> refers to a local network port. The web developer tools can then be accessed by launching a browser at the address http://localhost:<port_number>.
Alternatively, the environment variable QTWEBENGINE_REMOTE_DEBUGGING can be set. It can be set as either just a port working similarly to --remote-debugging-port or given both a host address and a port. The latter can be used to control which network interface to export the interface on, so that you can access the developer tools from a remote device.

1. 设置命令行参数

在windows命令行中输入如下参数,启动你的程序。

YourApp.exe --remote-debugging-port=16101

在这里插入图片描述
例如调试百度首页,打开百度后,在chrome浏览器里输入

http://localhost:16101

在这里插入图片描述
很熟悉的调试页面啊。
在这里插入图片描述

2. 设置环境变量

如下图所示,添加环境变量QTWEBENGINE_REMOTE_DEBUGGING,然后直接在Qt Create中debug运行即可,效果跟方法一中使用命令行参数相同。打开浏览器输入相应的端口即可,就不在贴图了。
在这里插入图片描述

总结

方法一适用于生产环境中,发现问题时的现场调试,方法二适用于开发过程中的调试。

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值