多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] > [therecipe/qt](https://github.com/therecipe/qt) > [examples](https://github.com/therecipe/examples) ## 安装教程 > [官方参考](https://github.com/therecipe/qt/wiki/Installation-on-Windows) ``` md go-qt && cd go-qt set GO111MODULE=on go mod init go-qt go get -v github.com/therecipe/qt go install -v -tags=no_env github.com/therecipe/qt/cmd/... //把之前下载的 therecipe/qt 转移到 vendor目录 go mod vendor // 在已有vendor时,进行 git clone,放置原来的vendor 被覆盖 git clone https://github.com.cnpmjs.org/therecipe/env_windows_amd64_513.git vendor/github.com/therecipe/env_windows_amd64_513 //注意最后输出的异常,并解决之 for /f %v in ('go env GOPATH') do %v\bin\qtsetup ``` ### 正式版(具有WebEngine / WebView支持) [参考](https://github.com/therecipe/qt/wiki/Installation-on-Windows#official-version-with-webenginewebview-support) ## 教程 1. 创建应用的方式可以通过 QML配置文件,也可以直接使用go代码,可通过 [base项目](https://github.com/therecipe/examples/tree/master/basic) 在个项目查看 2. 可支持交叉编译 ## 常用命令 ``` qtdeploy test desktop <含main.go目录> 直接运行 qtdeploy build desktop <含main.go目录> 编 ``` ## 实例 ### 自定义实例1 ``` md demo1 && cd demo1 //创建 main.go ``` <details> <summary>main.go</summary> ``` package main import ( "os" "github.com/therecipe/qt/widgets" ) func main() { // needs to be called once before you can start using the QWidgets app := widgets.NewQApplication(len(os.Args), os.Args) // create a window // with a minimum size of 250*200 // and sets the title to "Hello Widgets Example" window := widgets.NewQMainWindow(nil, 0) window.SetMinimumSize2(250, 200) window.SetWindowTitle("Hello Widgets Example") // create a regular widget // give it a QVBoxLayout // and make it the central widget of the window widget := widgets.NewQWidget(nil, 0) widget.SetLayout(widgets.NewQVBoxLayout()) window.SetCentralWidget(widget) // create a line edit // with a custom placeholder text // and add it to the central widgets layout input := widgets.NewQLineEdit(nil) input.SetPlaceholderText("Write something ...") widget.Layout().AddWidget(input) // create a button // connect the clicked signal // and add it to the central widgets layout button := widgets.NewQPushButton2("and click me!", nil) button.ConnectClicked(func(bool) { widgets.QMessageBox_Information(nil, "OK", input.Text(), widgets.QMessageBox__Ok, widgets.QMessageBox__Ok) }) widget.Layout().AddWidget(button) // make the window visible window.Show() // start the main Qt event loop // and block until app.Exit() is called // or the window is closed by the user app.Exec() } ``` </details> <br/> 运行 `qtdeploy test desktop demo1` ### 官方实例 > [examples](https://github.com/therecipe/examples) 注意如果报错,需要删除 examples 中的go.mod 文件,