1.下载安装QT

离线版QT地址:  https://download.qt.io/official_releases/qt/5.11/5.11.1/qt-opensource-windows-x86-5.11.1.exe

注意

最好全部安装,否则在后续的安装过程中会提示相应的文件找不到

2. 在环境变量中指定QT_DIR

默认的QT_DIR为C:\Qt

如果不指定QT_DIR,在后续安装过程中会出现如下错误

3. 将g++所在路径加入环境变量PATH中

  1. C:\Qt\Qt5.11.1\Tools\mingw530_32\bin
  2. C:\Qt\Qt5.11.1\5.11.\mingw53_32\bin
  3. C:\Qt\Qt5.11.1\Tools\mingw530_32\opt\bin

  1. C:\Qt\Qt5.11.1\Tools\mingw530_32\bin 目录下包含了gccg++等编译链接工具
  1. C:\Qt\Qt5.11.1\5.11.1\mingw53_32\bin 目录下包含了qmake.exe以及程序运行过程中需要的动态链接库(.dll)文件

4. 安装go

下载地址: https://golang.org/dl/

5. 下载安装therecipe/qt

  1. # 下载
  2. go get -v github.com/therecipe/qt/cmd/...
  3. # 安装
  4. %GOPATH%\bin\qtsetup.exe

安装过程中出现的硬链接失败可以忽略

生成的静态库所在路径为: %GOPATH%\pkg\windows_386\github.com\therecipe\qt

总共预计安装39个静态库文件(后缀名为.a)。其中安装成功38个,安装失败1个(winextras)。

安装记录如下:

  1. F:\>qtsetup
  2. [36mINFO[0m[] running: 'qtsetup prep'
  3. [31mERRO[0m[] failed to run command [31mcmd[0m="cmd /C mklink /H C:\\Go\\bin\\qtrcc.exe F:\\Workspace\\go\\bin\\qtrcc.exe" [31mdir[0m= [31menv[0m= [31merror[0m="exit status 1" [31mfunc[0m=RunCmdOptional [31mname[0m="failed to create qtrcc symlink in your PATH (C:\\Go\\bin\\qtrcc.exe); please use F:\\Workspace\\go\\bin\\qtrcc.exe instead"
  4. ϵͳ�޷����ļ��Ƶ���ͬ�Ĵ�����������
  5.  
  6. [31mERRO[0m[] failed to run command [31mcmd[0m="cmd /C mklink /H C:\\Go\\bin\\qtmoc.exe F:\\Workspace\\go\\bin\\qtmoc.exe" [31mdir[0m= [31menv[0m= [31merror[0m="exit status 1" [31mfunc[0m=RunCmdOptional [31mname[0m="failed to create qtmoc symlink in your PATH (C:\\Go\\bin\\qtmoc.exe); please use F:\\Workspace\\go\\bin\\qtmoc.exe instead"
  7. ϵͳ�޷����ļ��Ƶ���ͬ�Ĵ�����������
  8.  
  9. [31mERRO[0m[] failed to run command [31mcmd[0m="cmd /C mklink /H C:\\Go\\bin\\qtminimal.exe F:\\Workspace\\go\\bin\\qtminimal.exe" [31mdir[0m= [31menv[0m= [31merror[0m="exit status 1" [31mfunc[0m=RunCmdOptional [31mname[0m="failed to create qtminimal symlink in your PATH (C:\\Go\\bin\\qtminimal.exe); please use F:\\Workspace\\go\\bin\\qtminimal.exe instead"
  10. ϵͳ�޷����ļ��Ƶ���ͬ�Ĵ�����������
  11.  
  12. [31mERRO[0m[] failed to run command [31mcmd[0m="cmd /C mklink /H C:\\Go\\bin\\qtdeploy.exe F:\\Workspace\\go\\bin\\qtdeploy.exe" [31mdir[0m= [31menv[0m= [31merror[0m="exit status 1" [31mfunc[0m=RunCmdOptional [31mname[0m="failed to create qtdeploy symlink in your PATH (C:\\Go\\bin\\qtdeploy.exe); please use F:\\Workspace\\go\\bin\\qtdeploy.exe instead"
  13. ϵͳ�޷����ļ��Ƶ���ͬ�Ĵ�����������
  14.  
  15. [36mINFO[0m[] running: 'qtsetup check windows' [docker=false] [vagrant=false]
  16. [36mINFO[0m[] GOOS: 'windows'
  17. [36mINFO[0m[] GOARCH: 'amd64'
  18. [36mINFO[0m[] GOVERSION: 'go1.10.1'
  19. [36mINFO[0m[] GOROOT: * 'C:\Go\'
  20. [36mINFO[0m[] GOPATH: * 'F:\Workspace\go'
  21. [36mINFO[0m[] GOBIN: 'F:\Workspace\go\bin'
  22. [36mINFO[0m[] QT_HASH: 'd0f30a6e4c39e0989b1b00169b66abbca442becf'
  23. [36mINFO[0m[] QT_VERSION: '5.11.1'
  24. [36mINFO[0m[] QT_VERSION_MAJOR: '5.11.1'
  25. [36mINFO[0m[] QT_DIR: * 'C:\Qt\Qt5.11.1'
  26. [36mINFO[0m[] QT_STUB: 'false'
  27. [36mINFO[0m[] QT_DEBUG: 'false'
  28. [36mINFO[0m[] QT_QMAKE_DIR: ''
  29. [36mINFO[0m[] QT_WEBKIT: 'false'
  30. [36mINFO[0m[] QT_MSYS2: 'false'
  31. [36mINFO[0m[] running: 'qtsetup generate windows' [docker=false] [vagrant=false]
  32. [36mINFO[0m[] generating full qt/core
  33. [36mINFO[0m[] generating full qt/androidextras
  34. [36mINFO[0m[] generating full qt/gui
  35. [36mINFO[0m[] generating full qt/network
  36. [36mINFO[0m[] generating full qt/xml
  37. [36mINFO[0m[] generating full qt/dbus
  38. [36mINFO[0m[] generating full qt/nfc
  39. [36mINFO[0m[] generating full qt/script
  40. [36mINFO[0m[] generating full qt/sensors
  41. [36mINFO[0m[] generating full qt/positioning
  42. [36mINFO[0m[] generating full qt/widgets
  43. [36mINFO[0m[] generating full qt/sql
  44. [36mINFO[0m[] generating full qt/qml
  45. [36mINFO[0m[] generating full qt/websockets
  46. [36mINFO[0m[] generating full qt/xmlpatterns
  47. [36mINFO[0m[] generating full qt/bluetooth
  48. [36mINFO[0m[] generating full qt/webchannel
  49. [36mINFO[0m[] generating full qt/svg
  50. [36mINFO[0m[] generating full qt/multimedia
  51. [36mINFO[0m[] generating full qt/quick
  52. [36mINFO[0m[] generating full qt/help
  53. [36mINFO[0m[] generating full qt/location
  54. [36mINFO[0m[] generating full qt/scripttools
  55. [36mINFO[0m[] generating full qt/uitools
  56. [36mINFO[0m[] generating full qt/winextras
  57. [36mINFO[0m[] generating full qt/testlib
  58. [36mINFO[0m[] generating full qt/serialport
  59. [36mINFO[0m[] generating full qt/serialbus
  60. [36mINFO[0m[] generating full qt/printsupport
  61. [36mINFO[0m[] generating full qt/designer
  62. [36mINFO[0m[] generating full qt/scxml
  63. [36mINFO[0m[] generating full qt/gamepad
  64. [36mINFO[0m[] generating full qt/purchasing
  65. [36mINFO[0m[] generating full qt/datavisualization
  66. [36mINFO[0m[] generating full qt/charts
  67. [36mINFO[0m[] generating full qt/speech
  68. [36mINFO[0m[] generating full qt/quickcontrols2
  69. [36mINFO[0m[] generating full qt/sailfish
  70. [36mINFO[0m[] generating full qt/remoteobjects
  71. [36mINFO[0m[] running: 'qtsetup install windows' [docker=false] [vagrant=false]
  72. [36mINFO[0m[] installing full qt/core
  73. [36mINFO[0m[] installing full qt/androidextras
  74. [36mINFO[0m[] installing full qt/gui
  75. [36mINFO[0m[] installing full qt/network
  76. [36mINFO[0m[] installing full qt/xml
  77. [36mINFO[0m[] installing full qt/dbus
  78. [36mINFO[0m[] installing full qt/nfc
  79. [36mINFO[0m[] installing full qt/script
  80. [36mINFO[0m[] installing full qt/sensors
  81. [36mINFO[0m[] installing full qt/positioning
  82. [36mINFO[0m[] installing full qt/widgets
  83. [36mINFO[0m[] installing full qt/sql
  84. [36mINFO[0m[] installing full qt/qml
  85. [36mINFO[0m[] installing full qt/websockets
  86. [36mINFO[0m[] installing full qt/xmlpatterns
  87. [36mINFO[0m[] installing full qt/bluetooth
  88. [36mINFO[0m[] installing full qt/webchannel
  89. [36mINFO[0m[] installing full qt/svg
  90. [36mINFO[0m[] installing full qt/multimedia
  91. [36mINFO[0m[] installing full qt/quick
  92. [36mINFO[0m[] installing full qt/help
  93. [36mINFO[0m[] installing full qt/location
  94. [36mINFO[0m[] installing full qt/scripttools
  95. [36mINFO[0m[] installing full qt/uitools
  96. [36mINFO[0m[] installing full qt/winextras
  97. github.com/therecipe/qt
  98. github.com/therecipe/qt/winextras
  99. # github.com/therecipe/qt/winextras
  100. [36mINFO[0m[] installing full qt/testlib
  101. [36mINFO[0m[] installing full qt/serialport
  102. [36mINFO[0m[] installing full qt/serialbus
  103. [36mINFO[0m[] installing full qt/printsupport
  104. [36mINFO[0m[] installing full qt/designer
  105. [36mINFO[0m[] installing full qt/scxml
  106. [36mINFO[0m[] installing full qt/gamepad
  107. [36mINFO[0m[] installing full qt/purchasing
  108. [36mINFO[0m[] installing full qt/datavisualization
  109. [36mINFO[0m[] installing full qt/charts
  110. [36mINFO[0m[] installing full qt/speech
  111. [36mINFO[0m[] installing full qt/quickcontrols2
  112. [36mINFO[0m[] installing full qt/sailfish
  113. [36mINFO[0m[] installing full qt/remoteobjects
  114. [33mWARN[0m[0161] failed to install:
  115. [33mWARN[0m[0161] winextras
  116. [36mINFO [0m[] running: 'qtsetup test windows' [docker=false] [vagrant=false]
  117. [36mINFO [0m[] testing widgets\line_edits
  118. [36mINFO [0m[] testing widgets\pixel_editor
  119. [36mINFO [0m[] testing widgets\textedit
  120. [36mINFO [0m[] testing qml\application
  121. [36mINFO [0m[] testing qml\drawer_nav_x
  122. [36mINFO [0m[] testing qml\gallery
  123. [36mINFO [0m[] testing quick\calc

运行的测试代码所在目录源码目录(therecipe\qt)下的的internal\examples目录下。

6. 简单的程序

目录结构:

代码:

  1. package main
  2.  
  3. import (
  4. "os"
  5. "github.com/therecipe/qt/widgets"
  6. "github.com/therecipe/qt/gui"
  7. "github.com/therecipe/qt/core"
  8. )
  9.  
  10. func main() {
  11. // 创建应用程序
  12. app := widgets.NewQApplication(len(os.Args), os.Args)
  13. // 创建主窗口
  14. window := widgets.NewQWidget(nil, )
  15. // 设置窗口最小尺寸
  16. window.SetMinimumSize2(, )
  17. // 设置标题
  18. window.SetWindowTitle("hello QT, hello GO")
  19. mainLayout := widgets.NewQVBoxLayout()
  20. // 创建垂直布局
  21. window.SetLayout(mainLayout)
  22.  
  23. lineEidt := widgets.NewQLineEdit(nil)
  24.  
  25. //创建一个label,用于存放go logo
  26. icon := gui.NewQPixmap5("go.jpg", "", core.Qt__AutoColor)
  27. iconLabel := widgets.NewQLabel(nil, )
  28. iconLabel.SetPixmap(icon)
  29.  
  30. btn := widgets.NewQPushButton2("点我", nil)
  31. btn.ConnectClicked(func(bool) {
  32. widgets.QMessageBox_Information(nil, "我是对话框", "hello go,hello qt", widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
  33. })
  34.  
  35. // !!!! 注意是AddWidget 不是AddChildWidget
  36. mainLayout.AddWidget(lineEidt, , )
  37. mainLayout.AddWidget(iconLabel, , )
  38. window.Layout().AddWidget(btn)
  39.  
  40. // 显示窗口
  41. window.Show()
  42. // 进入消息循环
  43. app.Exec()
  44. }

main.go

生成目标exe文件

  1. 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

  1. #添加如下内容
  2. idea.max.intellisense.filesize=

由于静态库gui.a很大,因此需要提高goland智能补全所允许的 单个文件大小上限

2) 运行时内存不足

解决方法:

点击Goland 的开始菜单  Help > Edit Custom VM Options

根据配置 修改-Xmx选项,例如:

  1. -Xms512m
  2. -Xmx4096m
  3. -XX:ReservedCodeCacheSize=480m
  4. -XX:+UseConcMarkSweepGC
  5. -XX:SoftRefLRUPolicyMSPerMB=
  6. -ea
  7. -Dsun.io.useCanonCaches=false
  8. -Djava.net.preferIPv4Stack=true
  9. -XX:+HeapDumpOnOutOfMemoryError
  10. -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

windows下 go安装qt绑定的更多相关文章

  1. QT在windows下的安装与配置

    先了解Qt: Qt一直以来,分为商业.开源两个版本,商业版本为用户提供了二级制的动态库,直接安装既可以使用,但是需要花钱购买license,而开源版本则遵守GPL协议,提供了源码,用户需要自行编译,才 ...

  2. mediawiki在windows下的安装

    mediawiki在windows下的安装 对于刚接触wiki的朋友们来说,配置一个服务器环境,安装并运行mediawiki是一件很麻烦的事情,在这里,我尽量用通俗易懂的语言,介绍mw(mediawi ...

  3. Windows下GIT安装与使用(上传远程端)

    Windows下GIT安装与使用(上传远程服务器) 1.  登陆http://msysgit.github.io/并下载Git 2.  打开下载的exe文件,一路默认(路径可以去修改).有可能电脑需要 ...

  4. flume 1.7在windows下的安装与运行

    flume 1.7在windows下的安装与运行 一.安装 安装java,配置环境变量. 安装flume,flume的官网http://flume.apache.org/,下载地址,下载后直接解压即可 ...

  5. 关于在windows下部署发布QT程序的总结

    原文请看:http://www.cnblogs.com/javaexam2/archive/2011/05/18/2632916.html 关于在windows下部署发布QT程序的总结 2008-06 ...

  6. windows下python安装Numpy、Scipy、matplotlib模块(转载)

    python下载链接     Numpy下载链接 python中Numpy包的安装及使用 Numpy包的安装 准备工作 Python安装 pip安装 将pip所在的文件夹添加到环境变量path路径中 ...

  7. memcache的windows下的安装和简单使用

    原文:memcache的windows下的安装和简单使用 memcache是为了解决网站访问量大,数据库压力倍增的解决方案之一,由于其简单实用,很多站点现在都在使用memcache,但是memcach ...

  8. Windows下pry安装和配置

    Windows下pry安装和配置 pry是一个增强型的交互式命令行工具,比irb强大. 有自动完成功能,自动缩进,有颜色.有更强大的调试功能. pry 安装很简单. 在终端输入: gem instal ...

  9. Windows下虚拟机安装Mac OS X ----- VM12安装Mac OS X 10.11

    Windows下虚拟机安装Mac OS X -– VM12安装Mac OS X 10.11 随着Iphone在国内大行其道,越来越多的开发者涌入iOS开发大军 中,但都苦于没有苹果机,本文即将介绍WI ...

随机推荐

  1. 【原创】使用开源libimobiledevice盗取iphone信息

     一.概述     libimobiledevice可以理解为Linux系统下的iTunes,破解了iTunes的通信协议. 依赖:https://github.com/libimobiledevic ...

  2. vs2017激活码

    Visual Studio 2017(VS2017) 企业版 Enterprise 注册码:NJVYC-BMHX2-G77MM-4XJMR-6Q8QF Visual Studio 2017(VS201 ...

  3. Scrapy创建项目问题

    创建项目时报错 ModuleNotFoundError: No module named 'cryptography.hazmat.bindings._constant_time' pip insta ...

  4. silverlight 从数据库获取到数据,动态生成XMLWEN文件,并获取文件进行操作

    // Silverlight中的独立存储是其内部的可信任的可访问文件空间,在这里你可以使用Silverlight随意的创建.读取.写入.删除目录和文件,它有一些类似于Cookie,但是它可以在客户端保 ...

  5. QT下 enum转QString

    先在QT5.7 class EnumTest :public QObject { Q_OBJECT public: EnumTest(); enum PINYINENUM { XYDA, XYDB, ...

  6. 二叉搜索树(BST)的插入和删除递归实现

    思路 二叉搜索树的插入 TreeNode InsertRec(rootNode, key) = if rootNode == NULL, return new Node(key) if key > ...

  7. Python标准库之textwrap模块

    textwrap通过调整换行符的位置来格式化文本:以下是全部方法 __all__ = ['TextWrapper', 'wrap', 'fill', 'dedent', 'indent', 'shor ...

  8. hyperscan简单学习(2)

    对hyperscan官方的前两个example进行编译和运行. 支持单个和多个正则编译.并行匹配规则,性能高. 对块模式和流模式使用: 示例pcapscan: http://www.cnblogs.c ...

  9. calculate TajimaD in perl

    #!/usr/bin/perl use strict; use warnings; =pod--------------------------------------- this perl scri ...

  10. tab切换 原生js

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...