debugging - 如何在我的 QWebView 小部件中嵌入 Firebug Lite?

标签 debugging pyqt qwebview web-inspector firebug-lite

我已经开始将一些 QWebView 小部件嵌入到我的桌面应用程序 (PyQt) 中。
我使用 JQuery 和 CSS 来增强外观和可用性。
使用 Web 检查器调试我的 html 代码会很舒服。
如何将 Firebug Lite 嵌入到我的 QWebView 小部件中?

例如我尝试了以下代码,但它不起作用:

html1 = """
<html debug="true">
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.js"></script>
    <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js#startOpened=true"></script>
    <script type="text/javascript">
    $(document).ready(function() { 
        $("body").css("background", "#f00");
        console.log("in here");
    });
    </script>

</head>
<body><h1>Hello!</h1></body>
</html>
"""
html2 = """
<html debug="true">
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.js"></script>
    <script type="text/javascript">
    $(document).ready(function() { 
        $("body").css("background", "#f00");
        var firebugLite = document.createElement("script");
        firebugLite.src = "https://getfirebug.com/firebug-lite.js";
        firebugLite.id = "firebug_lite";
        firebugLite.textContent = "{ startOpened: true }";
        document.getElementsByTagName("head")[0].appendChild(firebugLite);
        console.log("in here");
    });
    </script>
</head>
<body><h1>Hello!</h1></body>
</html>
"""    

if __name__ == '__main__':
    app = QApplication(sys.argv)
    view = QWebView()
    frame = view.page().mainFrame()
    frame.setHtml(html2)
    view.show()
    app.exec_()

html1 和 html2 效果相同:body 变成红色,但 Firebug 不显示。

附注我的实际 html 代码无法使用外部客户端浏览器进行调试,
因为它使用 QT 资源和应用程序窗口对象。

最佳答案

我已将此 JavaScript 添加到我的基于 WebKit 的项目中,也许这对 QWebView 也有帮助?

var firebugLite = document.createElement("script");
firebugLite.src = "https://getfirebug.com/firebug-lite.js";
firebugLite.id = "firebug_lite";
firebugLite.textContent = "{ startOpened: true }";
document.getElementsByTagName("head")[0].appendChild(firebugLite);

关于debugging - 如何在我的 QWebView 小部件中嵌入 Firebug Lite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6398262/

相关文章:

qt - 如何在 QWebView/QWebPage 中实现 "back" Action

c++ - 如何为谷歌地图使用 QtWebview

windows - 禁止将 EXCEPTION_DEBUG_EVENT 传递给附加的调试器

c# - 如何使用 MDbg 以编程方式枚举正在运行的 .NET 进程中的类型?

python - PyQt:如何确定同时按下哪个鼠标按钮以及哪个 QTableView 的单元格?

python - 基于 Clicked 将单个 Python Def 用于多个 QpushButton

php - PHP解析/语法错误;以及如何解决它们

android - Eclipse 保持 Building workspace... 和 Building workspace... 和 Building workspace

qt - Qt 支持 'Open a folder and highlight a particular file' 吗?

c++ - 将 QLineEdit 添加到 qtcreator(设计器)中的 qtoolbar