windows下 go安裝qt綁定

 1.下載安裝QT

離線版QT地址:  https://download.qt.io/official_releases/qt/5.11/5.11.1/qt-opensource-windows-x86-5.11.1.exejava

注意android

最好所有安裝,不然在後續的安裝過程當中會提示相應的文件找不到git

 

2. 在環境變量中指定QT_DIR

默認的QT_DIR爲C:\Qtgithub

若是不指定QT_DIR,在後續安裝過程當中會出現以下錯誤golang

3. 將g++所在路徑加入環境變量PATH中

C:\Qt\Qt5.11.1\Tools\mingw530_32\bin
C:\Qt\Qt5.11.1\5.11.1\mingw53_32\bin
C:\Qt\Qt5.11.1\Tools\mingw530_32\opt\bin

C:\Qt\Qt5.11.1\Tools\mingw530_32\bin 目錄下包含了gcc、g++等編譯連接工具
C:\Qt\Qt5.11.1\5.11.1\mingw53_32\bin 目錄下包含了qmake.exe以及程序運行過程當中須要的動態連接庫(.dll)文件

4. 安裝go 

下載地址: https://golang.org/dl/web

5. 下載安裝therecipe/qt

# 下載
go get -v github.com/therecipe/qt/cmd/...
# 安裝
%GOPATH%\bin\qtsetup.exe

安裝過程當中出現的硬連接失敗能夠忽略sql

生成的靜態庫所在路徑爲: %GOPATH%\pkg\windows_386\github.com\therecipe\qtdocker

總共預計安裝39個靜態庫文件(後綴名爲.a)。其中安裝成功38個,安裝失敗1個(winextras)。windows

安裝記錄以下:websocket

F:\>qtsetup
INFO[0000] running: 'qtsetup prep'
ERRO[0000] failed to run command                         cmd="cmd /C mklink /H C:\\Go\\bin\\qtrcc.exe F:\\Workspace\\go\\bin\\qtrcc.exe" dir= env= error="exit status 1" func=RunCmdOptional name="failed to create qtrcc symlink in your PATH (C:\\Go\\bin\\qtrcc.exe); please use F:\\Workspace\\go\\bin\\qtrcc.exe instead"
ϵͳ�޷����ļ��Ƶ���ͬ�Ĵ�����������

ERRO[0000] failed to run command                         cmd="cmd /C mklink /H C:\\Go\\bin\\qtmoc.exe F:\\Workspace\\go\\bin\\qtmoc.exe" dir= env= error="exit status 1" func=RunCmdOptional name="failed to create qtmoc symlink in your PATH (C:\\Go\\bin\\qtmoc.exe); please use F:\\Workspace\\go\\bin\\qtmoc.exe instead"
ϵͳ�޷����ļ��Ƶ���ͬ�Ĵ�����������

ERRO[0000] failed to run command                         cmd="cmd /C mklink /H C:\\Go\\bin\\qtminimal.exe F:\\Workspace\\go\\bin\\qtminimal.exe" dir= env= error="exit status 1" func=RunCmdOptional name="failed to create qtminimal symlink in your PATH (C:\\Go\\bin\\qtminimal.exe); please use F:\\Workspace\\go\\bin\\qtminimal.exe instead"
ϵͳ�޷����ļ��Ƶ���ͬ�Ĵ�����������

ERRO[0000] failed to run command                         cmd="cmd /C mklink /H C:\\Go\\bin\\qtdeploy.exe F:\\Workspace\\go\\bin\\qtdeploy.exe" dir= env= error="exit status 1" func=RunCmdOptional name="failed to create qtdeploy symlink in your PATH (C:\\Go\\bin\\qtdeploy.exe); please use F:\\Workspace\\go\\bin\\qtdeploy.exe instead"
ϵͳ�޷����ļ��Ƶ���ͬ�Ĵ�����������

INFO[0000] running: 'qtsetup check windows' [docker=false] [vagrant=false]
INFO[0000] GOOS:                        'windows'
INFO[0000] GOARCH:                      'amd64'
INFO[0000] GOVERSION:                   'go1.10.1'
INFO[0000] GOROOT:                   *  'C:\Go\'
INFO[0000] GOPATH:                   *  'F:\Workspace\go'
INFO[0000] GOBIN:                       'F:\Workspace\go\bin'
INFO[0000] QT_HASH:                     'd0f30a6e4c39e0989b1b00169b66abbca442becf'
INFO[0000] QT_VERSION:                  '5.11.1'
INFO[0000] QT_VERSION_MAJOR:            '5.11.1'
INFO[0000] QT_DIR:                   *  'C:\Qt\Qt5.11.1'
INFO[0000] QT_STUB:                     'false'
INFO[0000] QT_DEBUG:                    'false'
INFO[0000] QT_QMAKE_DIR:                ''
INFO[0000] QT_WEBKIT:                   'false'
INFO[0000] QT_MSYS2:                    'false'
INFO[0000] running: 'qtsetup generate windows' [docker=false] [vagrant=false]
INFO[0006] generating full qt/core
INFO[0013] generating full qt/androidextras
INFO[0013] generating full qt/gui
INFO[0036] generating full qt/network
INFO[0039] generating full qt/xml
INFO[0041] generating full qt/dbus
INFO[0043] generating full qt/nfc
INFO[0044] generating full qt/script
INFO[0046] generating full qt/sensors
INFO[0049] generating full qt/positioning
INFO[0050] generating full qt/widgets
INFO[0071] generating full qt/sql
INFO[0073] generating full qt/qml
INFO[0075] generating full qt/websockets
INFO[0076] generating full qt/xmlpatterns
INFO[0078] generating full qt/bluetooth
INFO[0080] generating full qt/webchannel
INFO[0081] generating full qt/svg
INFO[0083] generating full qt/multimedia
INFO[0089] generating full qt/quick
INFO[0092] generating full qt/help
INFO[0095] generating full qt/location
INFO[0096] generating full qt/scripttools
INFO[0097] generating full qt/uitools
INFO[0099] generating full qt/winextras
INFO[0100] generating full qt/testlib
INFO[0101] generating full qt/serialport
INFO[0102] generating full qt/serialbus
INFO[0104] generating full qt/printsupport
INFO[0106] generating full qt/designer
INFO[0110] generating full qt/scxml
INFO[0112] generating full qt/gamepad
INFO[0113] generating full qt/purchasing
INFO[0114] generating full qt/datavisualization
INFO[0117] generating full qt/charts
INFO[0122] generating full qt/speech
INFO[0123] generating full qt/quickcontrols2
INFO[0124] generating full qt/sailfish
INFO[0124] generating full qt/remoteobjects
INFO[0125] running: 'qtsetup install windows' [docker=false] [vagrant=false]
INFO[0125] installing full qt/core
INFO[0126] installing full qt/androidextras
INFO[0127] installing full qt/gui
INFO[0128] installing full qt/network
INFO[0128] installing full qt/xml
INFO[0129] installing full qt/dbus
INFO[0130] installing full qt/nfc
INFO[0131] installing full qt/script
INFO[0131] installing full qt/sensors
INFO[0132] installing full qt/positioning
INFO[0133] installing full qt/widgets
INFO[0134] installing full qt/sql
INFO[0135] installing full qt/qml
INFO[0136] installing full qt/websockets
INFO[0136] installing full qt/xmlpatterns
INFO[0137] installing full qt/bluetooth
INFO[0138] installing full qt/webchannel
INFO[0138] installing full qt/svg
INFO[0139] installing full qt/multimedia
INFO[0140] installing full qt/quick
INFO[0141] installing full qt/help
INFO[0141] installing full qt/location
INFO[0142] installing full qt/scripttools
INFO[0143] installing full qt/uitools
INFO[0144] installing full qt/winextras
github.com/therecipe/qt
github.com/therecipe/qt/winextras
# github.com/therecipe/qt/winextras
INFO[0151] installing full qt/testlib
INFO[0152] installing full qt/serialport
INFO[0152] installing full qt/serialbus
INFO[0153] installing full qt/printsupport
INFO[0154] installing full qt/designer
INFO[0155] installing full qt/scxml
INFO[0155] installing full qt/gamepad
INFO[0156] installing full qt/purchasing
INFO[0157] installing full qt/datavisualization
INFO[0157] installing full qt/charts
INFO[0158] installing full qt/speech
INFO[0159] installing full qt/quickcontrols2
INFO[0160] installing full qt/sailfish
INFO[0160] installing full qt/remoteobjects
WARN[0161] failed to install: WARN[0161] winextras
 [36mINFO [0m[0953] running: 'qtsetup test windows' [docker=false] [vagrant=false]
 [36mINFO [0m[0953] testing widgets\line_edits
 [36mINFO [0m[1008] testing widgets\pixel_editor
 [36mINFO [0m[1054] testing widgets\textedit
 [36mINFO [0m[1225] testing qml\application
 [36mINFO [0m[1272] testing qml\drawer_nav_x
 [36mINFO [0m[1334] testing qml\gallery
 [36mINFO [0m[1384] testing quick\calc

運行的測試代碼所在目錄源碼目錄(therecipe\qt)下的的internal\examples目錄下。

 

6. 簡單的程序

目錄結構:

 

代碼:

package main

import (
    "os"
    "github.com/therecipe/qt/widgets"
    "github.com/therecipe/qt/gui"
    "github.com/therecipe/qt/core"
)

func main() {
    // 建立應用程序
    app := widgets.NewQApplication(len(os.Args), os.Args)
    // 建立主窗口
    window := widgets.NewQWidget(nil, 0)
    // 設置窗口最小尺寸
    window.SetMinimumSize2(400, 200)
    // 設置標題
    window.SetWindowTitle("hello QT, hello GO")
    mainLayout := widgets.NewQVBoxLayout()
    // 建立垂直佈局
    window.SetLayout(mainLayout)

    lineEidt := widgets.NewQLineEdit(nil)

    //建立一個label,用於存放go logo
    icon := gui.NewQPixmap5("go.jpg", "", core.Qt__AutoColor)
    iconLabel := widgets.NewQLabel(nil, 0)
    iconLabel.SetPixmap(icon)

    btn := widgets.NewQPushButton2("點我", nil)
    btn.ConnectClicked(func(bool) {
        widgets.QMessageBox_Information(nil, "我是對話框", "hello go,hello qt", widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
    })

    // !!!! 注意是AddWidget 不是AddChildWidget
    mainLayout.AddWidget(lineEidt, 0, 0)
    mainLayout.AddWidget(iconLabel, 0, 0)
    window.Layout().AddWidget(btn)

    // 顯示窗口
    window.Show()
    // 進入消息循環
    app.Exec()
}
main.go

生成目標exe文件

F:\Workspace\go\src\gui\qt>qtdeploy build desktop hello

須要將go.jpg拷貝至hello\deploy\windows\目錄下(與hello.exe處於一個目錄下)方可正常運行。

運行效果

 

 遇到的問題:

1) "xxx/src/github.com/therecipe/qt/gui" has no buildable Go source files

 

 解決方法:

點擊 Help > Edit Custom Properties

#添加以下內容
idea.max.intellisense.filesize=99999

 

因爲靜態庫gui.a很大,所以須要提升goland智能補全所容許的 單個文件大小上限

 

2) 運行時內存不足

 

解決方法:

點擊Goland 的開始菜單  Help > Edit Custom VM Options

根據配置 修改-Xmx選項,例如:

-Xms512m
-Xmx4096m
-XX:ReservedCodeCacheSize=480m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow

 -Xmx value limits the maximum heap memory size that the JVM can allocate.

參考:

https://github.com/therecipe/qt/wiki/Getting-Started

https://github.com/therecipe/qt/wiki/Installation-on-Windows

https://github.com/therecipe/qt/issues/90

https://stackoverflow.com/questions/23057988/file-size-exceeds-configured-limit-2560000-code-insight-features-not-availabl 

相關文章
相關標籤/搜索