go-qt

Install

环境

  • macOS Monterey 12.1
  • go1.17.5
  • therecipe/qt
  • therecipe/env_darwin_amd64_513 (Qt5.13)
  • Xcode v13.2 / xcode-select –install

therecipe/qt 安装

In GOPATH (global installation) mode (推荐使用这个)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
export GO111MODULE=off; xcode-select --install; go get -v github.com/therecipe/qt/cmd/... && $(go env GOPATH)/bin/qtsetup test && $(go env GOPATH)/bin/qtsetup -test=false

xcode-select: error: command line tools are already installed, use "Software Update" to install updates
github.com/therecipe/env_darwin_amd64_513 (download)

INFO[0000] running: 'qtsetup test darwin' [docker=false] [vagrant=false]
INFO[0000] testing showcases/wallet
INFO[0073] testing qml/gallery
INFO[0094] testing quick/calc
INFO[0113] testing widgets/textedit
INFO[0000] running: 'qtsetup prep'
INFO[0000] successfully created qtrcc symlink in your PATH (/usr/local/bin/qtrcc)
INFO[0000] successfully created qtmoc symlink in your PATH (/usr/local/bin/qtmoc)
INFO[0000] successfully created qtminimal symlink in your PATH (/usr/local/bin/qtminimal)
INFO[0000] successfully created qtdeploy symlink in your PATH (/usr/local/bin/qtdeploy)
INFO[0000] running: 'qtsetup check darwin' [docker=false] [vagrant=false]
INFO[0000] GOOS: 'darwin'
INFO[0000] GOARCH: 'amd64'
INFO[0000] GOVERSION: 'go1.17.5'
INFO[0000] GOROOT: '/Users/foo/.gobrew/versions/1.17.5/go'
INFO[0000] GOPATH: '/Users/foo/go'
INFO[0000] GOBIN: '/Users/foo/go/bin'
INFO[0000] GOMOD: ''
INFO[0000] QT_HASH: 'c0c124a5770d357908f16fa57e0aa0ec6ccd3f91'
INFO[0000] QT_API: ''
INFO[0000] QT_VERSION: '5.13.0'
INFO[0000] QT_DIR: * '/Users/foo/go/src/github.com/therecipe/env_darwin_amd64_513'
INFO[0000] QT_STUB: 'false'
INFO[0000] QT_DEBUG: 'false'
INFO[0000] QT_QMAKE_DIR: ''
INFO[0000] QT_WEBKIT: 'false'
INFO[0000] QT_STATIC: 'false'
INFO[0000] QT_GEN_GO: 'false'
INFO[0000] QT_GEN_OPENGL: 'false'
INFO[0000] QT_GEN_QUICK_EXTRAS: 'false'
INFO[0000] QT_RESOURCES_BIG: 'false'
INFO[0000] QT_NOT_CACHED: 'false'
INFO[0000] QT_HOMEBREW: 'false'
INFO[0000] QT_MACPORTS: 'false'
INFO[0000] QT_NIX: 'false'
INFO[0000] QT_FELGO: 'false'
INFO[0000] XCODE_DIR: '/Applications/Xcode.app'
INFO[0000] QT_PKG_CONFIG: 'false'
INFO[0000] running: 'qtsetup generate darwin' [docker=false] [vagrant=false]
INFO[0003] generating full qt/core
INFO[0017] generating full qt/androidextras
INFO[0018] generating full qt/gui
INFO[0034] generating full qt/network
INFO[0039] generating full qt/xml
INFO[0041] generating full qt/dbus
INFO[0043] generating full qt/nfc
INFO[0045] generating full qt/script
INFO[0046] generating full qt/sensors
INFO[0051] generating full qt/positioning
INFO[0053] generating full qt/widgets
INFO[0090] generating full qt/sql
INFO[0093] generating full qt/macextras
INFO[0094] generating full qt/qml
INFO[0097] generating full qt/websockets
INFO[0098] generating full qt/xmlpatterns
INFO[0099] generating full qt/bluetooth
INFO[0102] generating full qt/webchannel
INFO[0103] generating full qt/svg
INFO[0105] generating full qt/multimedia
INFO[0119] generating full qt/quick
INFO[0124] generating full qt/help
INFO[0128] generating full qt/location
INFO[0130] generating full qt/scripttools
INFO[0131] generating full qt/uitools
INFO[0132] generating full qt/webengine
INFO[0135] generating full qt/testlib
INFO[0136] generating full qt/serialport
INFO[0137] generating full qt/serialbus
INFO[0139] generating full qt/printsupport
INFO[0142] generating full qt/designer
INFO[0146] generating full qt/scxml
INFO[0148] generating full qt/gamepad
INFO[0150] generating full qt/purchasing
INFO[0151] generating full qt/datavisualization [GPLv3]
INFO[0157] generating full qt/charts [GPLv3]
INFO[0167] generating full qt/virtualkeyboard [GPLv3]
INFO[0169] generating full qt/speech
INFO[0170] generating full qt/quickcontrols2
INFO[0171] generating full qt/sailfish
INFO[0171] generating full qt/webview
INFO[0171] generating full qt/remoteobjects
INFO[0175] running: 'qtsetup install darwin' [docker=false] [vagrant=false]
INFO[0175] installing full qt/core
INFO[0176] installing full qt/androidextras
INFO[0176] installing full qt/gui
INFO[0176] installing full qt/network
INFO[0177] installing full qt/xml
INFO[0177] installing full qt/dbus
INFO[0177] installing full qt/nfc
INFO[0178] installing full qt/script
INFO[0178] installing full qt/sensors
INFO[0178] installing full qt/positioning
INFO[0178] installing full qt/widgets
INFO[0179] installing full qt/sql
INFO[0180] installing full qt/macextras
INFO[0180] installing full qt/qml
INFO[0180] installing full qt/websockets
INFO[0181] installing full qt/xmlpatterns
INFO[0181] installing full qt/bluetooth
INFO[0181] installing full qt/webchannel
INFO[0182] installing full qt/svg
INFO[0182] installing full qt/multimedia
INFO[0183] installing full qt/quick
INFO[0184] installing full qt/help
INFO[0185] installing full qt/location
INFO[0185] installing full qt/scripttools
INFO[0186] installing full qt/uitools
INFO[0186] installing full qt/webengine
INFO[0187] installing full qt/testlib
INFO[0188] installing full qt/serialport
INFO[0188] installing full qt/serialbus
INFO[0188] installing full qt/printsupport
INFO[0189] installing full qt/designer
INFO[0189] installing full qt/scxml
INFO[0190] installing full qt/gamepad
INFO[0190] installing full qt/purchasing
INFO[0190] installing full qt/datavisualization [GPLv3]
INFO[0191] installing full qt/charts [GPLv3]
INFO[0191] installing full qt/virtualkeyboard [GPLv3]
INFO[0192] installing full qt/speech
INFO[0192] installing full qt/quickcontrols2
INFO[0192] installing full qt/sailfish
INFO[0193] installing full qt/webview
INFO[0193] installing full qt/remoteobjects
INFO[0193] installing full qt/internal/binding/runtime

In Module (per project) mode (to work around the GFW you can use a proxy like this: GOPROXY=https://goproxy.io)

1
export GO111MODULE=on; xcode-select --install; go get -v github.com/therecipe/qt && go install -v -tags=no_env github.com/therecipe/qt/cmd/... && go mod vendor && git clone https://github.com/therecipe/env_darwin_amd64_513.git vendor/github.com/therecipe/env_darwin_amd64_513 && $(go env GOPATH)/bin/qtsetup

deploy 打包

  • therecipe/qt 打包方式是使用 vendor 目录打包,而不是使用最新的 go mod。我们要把所有的依赖放到 vendor 目录下
1
go mod vendor
  • 克隆环境依赖
1
git clone https://github.com/therecipe/env_$(go env GOOS)_amd64_513.git vendor/github.com/therecipe/env_$(go env GOOS)_amd64_513
  • 编译
1
2
3
qtdeploy build dektop
or
qtdeploy test desktop

交叉编译

使用 Docker 容器交叉编译。

1
2
3
4
# 编译 windows_64_shared 版本
qtdeploy -docker build windows
# 编译 windows_64_static 版本
qtdeploy -docker build windows_64_static

reference

macOS 下搭建 golang 的 QT 开发环境

Go 语言 QT 开发踩坑

Qt 开发之 Go 篇(一)

系列文章 Golang-Qt5

Go (Golang) | Qt5 GUI 開發