Golang has been considered to have no good GUI libraries, and that is not the case.
There are currently GOTK3:HTTPS://GITHUB.COM/GOTK3/GOTK3 based on gtk+3.0.
And then we're going to say QT:HTTPS://GITHUB.COM/THERECIPE/QT, which is based on the latest QT5 (5.11) unofficial binding.
Reasons to choose QT
the reason for choosing THERECIPE/QT is first because the API it provides is almost the same as native Qt and other binding (such as PYQT5) (a few differences I will explain in the following articles carefully);
The second is because the author update very diligent, bug repair more timely;
Finally, because QT is a broad-based framework, the documentation is comprehensive and the community is active, and it's easier to solve any problems if you're faced with them.
Cross-platform support:
Why not GOTK3?
Gtk+3 is also a broad cross-platform GUI framework, which is also rich in functionality and is maintained by a group of great developers.
However, compared with the size of Qt slightly smaller, and GTK + and Python as there are 2 and 32 versions of the bridge-like leap, from gtk+2 to 3 will encounter a lot of small trouble;
GTK + 's documentation is not as exhaustive as QT, and GOTK3 maintenance is not active.
Most importantly, GOTK3 uses additional APIs for concurrent use and does not work directly with Goroutine.
As for callback VS Signal/slot, I am not a cold person, I personally have GTK+/GTKMM and Qt is the use of experience, experience tells me that using QT will be a lot easier.
So based on the above reasons, I chose therecipe/qt this library.
Installation
The next step is how to install the QT Golang binding.
We have some work to do before go get.
First is the installation of the complete Qt5, why to complete the installation, because this library does not choose to install the module function, the lack of modules will be used in the future to output a large number of error information, I have a neat clean terminal output, so all installed security, if you do not feel very comfortable, Can actively mention issues or technology Daniel can directly submit PR participation contribution:-P. QT Download Address: https://download.qt.io/official_releases/online_installers
QT needs to be installed in your $home directory , in order to avoid problems in the future, because THERECIPE/QT use QT, you need to generate some tools in the Qmake bin directory, if your QT installed in the non-hoome directory, It is very likely that the use of permissions, so that the compiled library only the rights of the user can use, so it is recommended to install Qt5.11 in your $home, and in the next installation please do not use sudo and other commands.
Because the QT source files will be installed, so there will be a certain lag in the installation, wait a while.
Then configure the QT environment, modify your ~/.bash_profile,~/.profile, modify the source ~/.bash_profile, or log out the user to log back in to make the configuration effective (of course, rebooting the system).
To modify an example:
# ~/. bash_profile# Therecipe/environment variables required by QT export Qt_dir='/home/user name/qt5.11.1'# directory to install QT export qt_version='5.11.1'# QT version number export Qt_debug=false# Whether to enable Debugexport qt_stub=false# Memory is less than 2Gb or 32-bit systems need to set true# go1.TenCGO environments settings required when using go1.10 export Cgo_cxxflags_allow=".*"Export Cgo_ldflags_allow=".*"Export Cgo_cflags_allow=".*"
In addition to having g++5.0+ and some OpenGL dependencies
# debian/installation commands for UbuntusudoApt-get-yInstallBuild-essential Libglu1-mesa-dev Libpulse-dev libglib2.0-dev# Fedora/rhel/CentOSsudo Yum-Y Groupinstall"C Development Tools and Libraries"sudo Yum-YInstallMesa-libglu-devel gstreamer-plugins-base Pulseaudio-libs-devel glib2-devel# OpenSUSEsudoZypper-nInstall-T-pattern devel_basis# Arch LinuxsudoPacman-s Base-devel
Once these preparations are done, you can start installing THERECIPE/QT.
Here are the installation methods on Liunx, because I write code on Linux,
Other systems please visit here: windows:https://github.com/therecipe/qt/wiki/installation-on-windows, macos:https://github.com/ Therecipe/qt/wiki/installation-on-macos.
Install Qt-tools:
Go get-u-v github.com/therecipe/qt/cmd/...
Then install the bindings and remember to stay away from sudo!!!
$GOPATH/bin/qtsetup
Generating the binding requires compiling some QT source files, so it takes a while for the installation to start with several sample programs.
The overall installation requires less than 6Gb of disk space (varies from person to person).
Now that the installation is complete, we can import github.com/therecipe/qt/widgets in the program to use a variety of QT components.
However, to run your program, it is not possible to use go build because the library uses MOC technology, and the next blog will show you how to compile the Golang code that uses QT.
Reference:
Https://github.com/therecipe/qt/wiki/Installation
Https://github.com/therecipe/qt/wiki/Installation-on-Linux