使用Ubuntu SDK调试HTML5
我读到了这个问题: 我可以为Ubuntu手机开发混合原生/ HTML5应用程序吗?
它有一个很好的答案,但Ubuntu SDK(Ubuntu 13.04)不再支持它,现在它使用:
import QtQuick 2.0 import Ubuntu.Components 0.1 import QtWebKit 3.0
尝试调用WebView的“设置”时有一些错误:
Cannot assign to non-existent property "settings"
在网上挖掘我发现了一些解决方案,遗憾的是对我不起作用。
import QtQuick 2.0 import Ubuntu.Components 0.1 import QtWebKit 3.0 import QtWebKit.experimental 1.0 MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the .desktop filename applicationName: "Gastos" width: units.gu(100) height: units.gu(75) Page { id: page title: "HTML5 App" Flickable { id: webViewFlickable anchors.fill: parent WebView { experimental.preferences.developerExtrasEnabled: true experimental.preferences.javascriptEnabled: true id: webView anchors.fill: parent url: "html/index.html" onTitleChanged: { page.title = title; } } } } }
显示了一些警告,但它开始很好。
WARNING: This project is using the experimental QML API extensions for QtWebKit and is therefore tied to a specific QtWebKit release. WARNING: The experimental API will change from version to version, or even be removed. You have been warned!
但是没有开发者工具。 右键单击不起作用,也许我错过了什么? 任何帮助将不胜感激。
提前致谢
诀窍是使用WebKit的远程检查器。 以下是我在QtCreator 3.0中使用它的方法:
- 如果您还没有Google Chrome,请下载它。 (我相信Safari也有效。)
- 在QtCreator中,单击左列中的“项目”,然后单击顶部的“运行”选项卡。
- 在“运行环境”旁边,单击“详细信息”下拉列表。
- 单击“添加”以添加新的环境变量。
- 设置名为QTWEBKIT_INSPECTOR_SERVER的变量,并将值设置为任何未使用的本地端口号,例如9999
- 运行您的项目
- 打开Chrome并输入以下url:
http://127.0.0.1:9999
:http://127.0.0.1:9999
:http://127.0.0.1:9999
可能需要一点时间才能出现。 如果URL不起作用,您可以使用Microsoft TCPView(在Windows上)等工具来确保您的进程打开端口。
在Qt中启用远程检查器的技巧来自这篇文章: https : //lists.webkit.org/pipermail/webkit-qt/2012-April/002646.html
从ubuntu-html5-theme软件包版本14.04.20140123-ppa2(Trusty)开始,可以添加--inspector
参数来启动HTML5应用程序。 (这可以添加到shell中的ubuntu-html5-app-launcher
命令中,并通过在SDK中设置运行配置)。
使用--inspector
参数,应用程序的shell输出显示IP地址和端口。 您可以在WebKit浏览器(例如铬浏览器)中打开此URL,您将看到一个“可检查视图”,其中包含可用于查看警告,错误和调试的JavaScript控制台。 这允许您使用您可能已经熟悉的基于浏览器的HTML工具。
这是从shell启动应用程序的示例:
$ ubuntu-html5-app-launcher --www=HTML5_APP_PROJECT_DIR --inspector
以下是输出的一部分,其中包含您需要查找的URL:
Inspector server started successfully. Try pointing a WebKit browser to http://192.168.1.105:9221
如上所述,您还可以配置Ubuntu SDK以执行相同的操作。 查看Projects> Run Settings区域并配置Run Configuration,如下所示: