使用Go语言开发Qt界面_go qt_kuokay的博客-优快云博客
# Go的环境变量配置,配置过一次就不用在设置了
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn
go的版本是1.19.2
# 下载therecipe/qt库
go get -v -tags=no_env github.com/therecipe/qt/cmd/...
windows 就是系统变量
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() }