go qt的设置(windows)

本文介绍了如何使用Go语言的goqt库创建Qt界面应用程序。首先,配置Go的环境变量,然后下载therecipe/qt库。接着,展示了一个简单的Go程序,创建了一个包含输入框和按钮的窗口。当按钮被点击时,会显示一个信息对话框显示输入框的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用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()
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值