問題背景
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運行即可,效果跟方法一中使用命令行參數相同。打開瀏覽器輸入相應的端口即可,就不在貼圖了。
總結
方法一適用於生產環境中,發現問題時的現場調試,方法二適用於開發過程中的調試。
————————————————
版權聲明:本文為CSDN博主「blueshaw」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/shawzg/article/details/102967768