当前位置: 首页 > news >正文

网站制作主题/百度问答平台

网站制作主题,百度问答平台,加强经管学院网站建设,建设商业门户网站的重要在前面的文章“使用golang来设计我们的Ubuntu Scope”中,我们已经介绍了如何利用golang来开发Ubuntu Scope。在今天的文章中,我们来简单介绍一下如何使用golang来开发QML应用。这对于一些熟悉golang语言的,但是不是很熟悉C的开发这来说&#…

在前面的文章“使用golang来设计我们的Ubuntu Scope”中,我们已经介绍了如何利用golang来开发Ubuntu Scope。在今天的文章中,我们来简单介绍一下如何使用golang来开发QML应用。这对于一些熟悉golang语言的,但是不是很熟悉C++的开发这来说,无疑是一个好的选择。虽然我们大多数的QML应用只需要QML加上一些Javascript的脚本即可,但是我们可以使用Qt C++或Go语言来拓展它的功能,来做一些需要计算或特殊功能的部分。


首先,我们来查看我们中国开发者dawndiy所做的一个repository:


https://github.com/dawndiy/ubuntu-go-qml-template


这个repository是基于另外一个repository: https://github.com/go-qml/qml.有兴趣的开发者也可以参阅另外一个repository https://github.com/salviati/go-qt5.这也是一个非常有意思的一个项目.


首先就像dawndiy在它的github里描述的那样:


安装Ubuntu SDK


我们按照连接“http://developer.ubuntu.com/start/ubuntu-sdk/installing-the-sdk/”来安装我们自己的SDK。我们也可以参照我的博客文章“Ubuntu SDK 安装”。


安装额外的包

$sudo apt-get install golang g++ qtdeclarative5-dev qtbase5-private-dev qtdeclarative5-private-dev libqt5opengl5-dev qtdeclarative5-qtquick2-plugin

这些包是为了我们能够成功编译我们的Go+QML应用所必须的。


设置chroots


如果你已经在上面参照“Ubuntu SDK 安装”来安装自己的SDK的话,这部分的很多部分已经做了。我们执行如下的指令:

$git clone https://github.com/nikwen/ubuntu-go-qml-template.git
$cd ubuntu-go-qml-template
$chroot-scripts/setup-chroot.sh

我们可以在我们自己喜欢的目录中做上面的事情。在实际的操作中,我发现如果在没有VPN的情况下,安装可能不能成功,原因是它需要访问“storage.googleapis.com”网址来下载一些东西。不过这没关系,你们可以到dawndiy的github里下载。那里已经有你所需要的所有的东西。


我们来看一下setup-chroot.sh:

#!/bin/bashDIR=$(dirname $(readlink -f "$0"))echo "====================================="
echo "========== Creating chroot =========="
echo "====================================="
echosudo click chroot -a armhf -f ubuntu-sdk-14.10 -s utopic create
sudo click chroot -a armhf -f ubuntu-sdk-14.10 -s utopic upgradeecho
echo "====================================="
echo "=== Installing packages in chroot ==="
echo "====================================="
echosudo click chroot -a armhf -f ubuntu-sdk-14.10 -s utopic maint apt-get install git qtdeclarative5-dev:armhf qtbase5-private-dev:armhf qtdeclarative5-private-dev:armhf libqt5opengl5-dev:armhf qtdeclarative5-qtquick2-plugin:armhfGO_DIR=$DIR/../go-installationmkdir -p $GO_DIR
cd $GO_DIR$DIR/install-go-1-3-3.sh


在这里,我们可以看到它去下载ubuntu-sdk-14.10 的armhf。这个是为了来交叉汇编我们的应用,并编译ARM版本的可执行文件。当然我们可以设置为ubuntu-sdk-15.04。我们需要做一些改变。这个步骤一旦设置好了,就可以不用再做第二次了。


在Desktop下运行应用


$./run.sh

我们在Terminal中键入上面的命令,我们就可以在Desktop中看见如下的运行的应用:




应用中的qml文件可以在./share/ubuntu-go-qml-template/main.qml中找到:

main.qml

import QtQuick 2.0
import Ubuntu.Components 1.1/*!\brief MainView with a Label and Button elements.
*/MainView {// objectName for functional testing purposes (autopilot-qt5)objectName: "mainView"// Note! applicationName needs to match the "name" field of the click manifestapplicationName: "ubuntu-go-qml-template.nikwen"/*This property enables the application to change orientationwhen the device is rotated. The default is false.*///automaticOrientation: true// Removes the old toolbar and enables new features of the new header.useDeprecatedToolbar: falsewidth: units.gu(100)height: units.gu(75)Page {title: i18n.tr("Simple")Column {spacing: units.gu(1)anchors {margins: units.gu(2)fill: parent}Label {id: labelobjectName: "label"text: ctrl.message}Button {objectName: "button"width: parent.widthtext: i18n.tr("Tap me!")onClicked: ctrl.hello()}}}
}

在./src/ubuntu-go-qml-template/main.go,我们可以看到如下的代码:


package mainimport ("gopkg.in/qml.v1""log"
)func main() {err := qml.Run(run)if (err != nil) {log.Fatal(err)}
}func run() error {engine := qml.NewEngine()component, err := engine.LoadFile("share/ubuntu-go-qml-template/main.qml")if err != nil {return err}ctrl := Control{Message: "Hello from Go!"}context := engine.Context()context.SetVar("ctrl", &ctrl)win := component.CreateWindow(nil)ctrl.Root = win.Root()win.Show()win.Wait()return nil
}type Control struct {Root    qml.ObjectMessage string
}func (ctrl *Control) Hello() {go func() {if (ctrl.Message == "Hello from Go!") {ctrl.Message = "Hello from Go Again!"} else {ctrl.Message = "Hello from Go!"}qml.Changed(ctrl, &ctrl.Message)}()
}

具体关于这些golang的介绍,大家可以参考 http://godoc.org/gopkg.in/qml.v1。


部署到手机中


$./install-on-device.sh

我们使用上面的命令来部署我们的Go应用到手机中:



我们可以看到它的运行和在Desktop上面的是完全一样的。我们可以在如下的目录中找到我们所需要的click安装文件:

bin/ubuntu-go-qml-template.nikwen_0.1_armhf.click

所有的源码包括下载的库等: https://github.com/liu-xiao-guo/ubuntu-go-qml-template


http://www.lbrq.cn/news/1328797.html

相关文章:

  • 公司网站建设要注意什么/seo营销怎么做
  • 帮别人做网站怎么接单/软文范例100字以内
  • wordpress网站相册/小程序商城
  • 纯静态单页网站/网店代运营公司哪家好
  • 企业网站设计合同/湖北搜索引擎优化
  • 中关村在线网站的建设/青岛网站排名公司
  • wordpress列表插件/虞城seo代理地址
  • 网站开发工程师岗位说明书/站长工具排名分析
  • 北京高端网站建设公司/百度广告屏蔽
  • 网站建设检查/百度服务商平台
  • 北京最新新闻事件/北京网站seo优化推广
  • 日本 网站 设计 模仿欧美/营销软件app
  • 泰安网站的建设/网站链接分析工具
  • 网站建设的几种结构/高质量外链代发
  • 万江网站建设/直播营销策略有哪些
  • 自己做ppt网站吗/云南网络推广服务
  • vps wordpress忘记密码/东莞百度快速优化排名
  • wordpress网站不显示菜单/长尾关键词排名系统
  • 贵州做网站怎么推广/传播易广告投放平台
  • 棉桃剥壳机做网站/完善的seo网站
  • 旅游景区网站建设/营销型网站有哪些功能
  • 做网站上传那个目录/投稿平台
  • 网站开发的前台开发工具/抖音优化是什么意思
  • 重庆南坪网站建设咨询400/百度手机助手下载安卓
  • 天津做网站建设的公司/seo优化网站查询
  • 可做产品预售的网站/营销型企业网站诊断
  • 做行业网站投入/北京网站建设公司
  • 设计一个官方网站推广广告/武汉百度推广代运营
  • 国网典型设计最新版/seo顾问服务四川
  • wordpress 做网站/天津关键词排名推广
  • 《Java 程序设计》第 14 章 - JavaFX 基础
  • QT6 Python UI文件转换PY文件的方法
  • LLMs之Agent:GLM-4.5的简介、安装和使用方法、案例应用之详细攻略
  • SpringBoot集成deepseek
  • 【LLM】——qwen2.5 VL模型导出到onnx
  • 短剧小程序系统开发:连接创作者与用户的桥梁