注意:
- go get -u -v github.com/therecipe/qt/cmd/…
下载到后面似乎会出现timeout的问题,那是因为国外网址被强了;
我的MAC系统解决办法: 打开App Store 搜索VPN,可以找到几款试用版本哦。
- qt需要先安装,并且版本一定是你安装的版本,路径也必须设置正确,错的了话后面会出问题。
export QT_DIR='/home/用户名/Qt5.11.1' # 安装Qt的目录
export QT_VERSION='5.11.1' # Qt的版本号
- 最后必须执行qtsetup, 这个命令是上面下载的代码生成的,如果qt版本错误,或者路径设置错误,运行时会有error,仔细查看错误,再行修改,在运行qtsetup。
$ qtsetup
- 恭喜你,可以在go中运行qt代码了。
测试代码如下:
package main
import (
"os"
"github.com/therecipe/qt/widgets"
)
func main() {
showQtWindow()
}
func showQtWindow() {
app := widgets.NewQApplication(len(os.Args), os.Args)
window := widgets.NewQMainWindow(nil, 0)
window.SetMinimumSize2(250, 200)
window.SetWindowTitle("treeview Example")
widget := widgets.NewQWidget(nil, 0)
widget.SetLayout(widgets.NewQVBoxLayout())
window.SetCentralWidget(widget)
treeview := widgets.NewQTreeView(nil)
widget.Layout().AddWidget(treeview)
remove := widgets.NewQPushButton2("remove last item", nil)
remove.ConnectClicked(func(bool) {
})
widget.Layout().AddWidget(remove)
add := widgets.NewQPushButton2("add new item", nil)
add.ConnectClicked(func(bool) {
//model.Add(NewTreeItem(nil).initWith([]string{"john", "doe"}))
})
widget.Layout().AddWidget(add)
edit := widgets.NewQPushButton2("edit last item", nil)
edit.ConnectClicked(func(bool) {
//model.Edit("bob", "omb")
})
widget.Layout().AddWidget(edit)
window.Show()
app.Exec()
}