qt
Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
Top Related Projects
Quick Overview
therecipe/qt is a Go binding for the Qt framework, allowing developers to create cross-platform graphical user interfaces (GUIs) using Go programming language. It provides a comprehensive set of tools and libraries to build native-looking applications for desktop, mobile, and embedded systems.
Pros
- Enables Go developers to create GUI applications using the powerful Qt framework
- Supports cross-platform development for desktop, mobile, and embedded systems
- Provides access to a wide range of Qt modules and features
- Offers good performance due to the combination of Go's efficiency and Qt's optimized rendering
Cons
- Requires a relatively large dependency (Qt framework) to be installed
- Learning curve can be steep for developers not familiar with Qt concepts
- Documentation and community support may be less extensive compared to other Go GUI libraries
- May have occasional compatibility issues with newer Qt versions
Code Examples
- Creating a simple window:
package main
import (
"os"
"github.com/therecipe/qt/widgets"
)
func main() {
app := widgets.NewQApplication(len(os.Args), os.Args)
window := widgets.NewQMainWindow(nil, 0)
window.SetWindowTitle("Hello, Qt!")
window.SetMinimumSize2(300, 200)
window.Show()
app.Exec()
}
- Adding a button to the window:
button := widgets.NewQPushButton2("Click me!", nil)
button.ConnectClicked(func(checked bool) {
widgets.QMessageBox_Information(nil, "Info", "Button clicked!", widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
})
window.SetCentralWidget(button)
- Creating a layout with multiple widgets:
layout := widgets.NewQVBoxLayout()
label := widgets.NewQLabel2("Enter your name:", nil, 0)
layout.AddWidget(label, 0, 0)
input := widgets.NewQLineEdit(nil)
layout.AddWidget(input, 0, 0)
button := widgets.NewQPushButton2("Greet", nil)
button.ConnectClicked(func(checked bool) {
name := input.Text()
widgets.QMessageBox_Information(nil, "Greeting", "Hello, "+name+"!", widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
})
layout.AddWidget(button, 0, 0)
centralWidget := widgets.NewQWidget(nil, 0)
centralWidget.SetLayout(layout)
window.SetCentralWidget(centralWidget)
Getting Started
- Install Go and set up your Go workspace.
- Install Qt 5.12 or later.
- Install therecipe/qt:
go get -u github.com/therecipe/qt/cmd/...
- Set up the Qt environment:
$(go env GOPATH)/bin/qtsetup
- Create a new Go file with your Qt application code.
- Build and run your application:
$(go env GOPATH)/bin/qtdeploy build desktop . ./deploy/linux/myapp
Note: Replace "linux" with your target platform (windows, darwin, etc.) when running the built application.
Competitor Comparisons
QML support for the Go language
Pros of qml
- Focused specifically on QML bindings, potentially offering a more streamlined experience for QML-centric development
- Lighter weight and potentially easier to integrate for projects that only need QML functionality
- May have a simpler learning curve for developers primarily interested in QML
Cons of qml
- Limited to QML, lacking support for other Qt modules and widgets
- Potentially smaller community and fewer resources compared to the more comprehensive qt project
- May require additional libraries or tools for more complex Qt-based applications
Code Comparison
qt:
app := widgets.NewQApplication(len(os.Args), os.Args)
window := widgets.NewQMainWindow(nil, 0)
window.SetWindowTitle("Hello Qt")
window.Show()
app.Exec()
qml:
engine := qml.NewEngine()
component, err := engine.LoadFile("main.qml")
window := component.Create(nil)
window.Show()
engine.Wait()
Both examples demonstrate creating a window, but qt uses widgets while qml focuses on QML-based UI creation.
Golang bindings to the Qt cross-platform application framework.
Pros of goqt
- Lighter weight and more focused on Qt bindings for Go
- Potentially easier to use for developers familiar with Qt concepts
- More direct mapping to Qt classes and functions
Cons of goqt
- Less actively maintained compared to qt
- Smaller community and fewer resources available
- Limited documentation and examples
Code Comparison
qt:
package main
import (
"os"
"github.com/therecipe/qt/widgets"
)
func main() {
app := widgets.NewQApplication(len(os.Args), os.Args)
window := widgets.NewQMainWindow(nil, 0)
window.Show()
app.Exec()
}
goqt:
package main
import (
"os"
"github.com/kitech/qt.go/qtwidgets"
)
func main() {
app := qtwidgets.NewQApplication(len(os.Args), os.Args)
window := qtwidgets.NewQMainWindow(nil, 0)
window.Show()
app.Exec()
}
Both repositories provide Go bindings for Qt, but qt offers a more comprehensive and actively maintained solution with broader community support. goqt may be suitable for simpler projects or developers who prefer a more direct mapping to Qt classes. The code comparison shows similar syntax and structure, with the main difference being the import paths.
Platform-native GUI library for Go.
Pros of ui
- Lightweight and focused on simplicity
- Pure Go implementation without C++ dependencies
- Easier to get started for Go developers
Cons of ui
- Limited widget set compared to Qt
- Less mature and fewer features
- Smaller community and ecosystem
Code Comparison
ui:
window := ui.NewWindow("Hello", 200, 100, false)
button := ui.NewButton("Click Me")
window.SetChild(button)
window.OnClosing(func(*ui.Window) bool {
ui.Quit()
return true
})
qt:
app := widgets.NewQApplication(len(os.Args), os.Args)
window := widgets.NewQMainWindow(nil, 0)
button := widgets.NewQPushButton2("Click Me", nil)
window.SetCentralWidget(button)
window.Show()
app.Exec()
Summary
ui is a lightweight, pure Go GUI toolkit that's easy to use for Go developers. It offers simplicity but has limited widgets and features compared to qt. qt provides a comprehensive set of widgets and tools, leveraging the power of Qt, but requires C++ dependencies and has a steeper learning curve. Choose ui for simple Go applications with basic GUI needs, and qt for more complex, feature-rich desktop applications.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Introduction
Qt is a free and open-source widget toolkit for creating graphical user interfaces as well as cross-platform applications that run on various software and hardware platforms with little or no change in the underlying codebase.
Go, also known as Golang, is a programming language designed at Google.
therecipe/qt allows you to write Qt applications entirely in Go, JavaScript/TypeScript, Dart/Flutter, Haxe and Swift
Beside the language bindings provided, therecipe/qt
also greatly simplifies the deployment of Qt applications to various software and hardware platforms.
At the time of writing, almost all Qt functions and classes are accessible, and you should be able to find everything you need to build fully featured Qt applications.
Impressions
Gallery of example applications.
Installation
The following instructions assume that you already installed Go and Git
(Experimental) cgo-less version (try this first, if you are new and want to test the binding)
Windows
go get -ldflags="-w" github.com/therecipe/examples/basic/widgets && for /f %v in ('go env GOPATH') do %v\bin\widgets.exe
macOS/Linux
go get -ldflags="-w" github.com/therecipe/examples/basic/widgets && $(go env GOPATH)/bin/widgets
Default version
Windows (more info)
set GO111MODULE=off
go get -v github.com/therecipe/qt/cmd/... && for /f %v in ('go env GOPATH') do %v\bin\qtsetup test && %v\bin\qtsetup -test=false
macOS (more info)
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
Linux (more info)
export GO111MODULE=off; go get -v github.com/therecipe/qt/cmd/... && $(go env GOPATH)/bin/qtsetup test && $(go env GOPATH)/bin/qtsetup -test=false
Resources
- Installation
- Getting Started
- Wiki
- Qt Documentation
- FAQ
- #qt-binding Slack channel (invite)
Deployment Targets
Target | Arch | Linkage | Docker Deployment | Host OS |
---|---|---|---|---|
Windows | 32 / 64 | dynamic / static | Yes | Any |
macOS | 64 | dynamic | Yes | Any |
Linux | arm / arm64 / 64 | dynamic / static / system | Yes | Any |
Android (+Wear) | arm / arm64 | dynamic | Yes | Any |
Android-Emulator (+Wear) | 32 | dynamic | Yes | Any |
SailfishOS | arm | system | Yes | Any |
SailfishOS-Emulator | 32 | system | Yes | Any |
Raspberry Pi (1/2/3) | arm | dynamic / system | Yes | Any |
Ubuntu Touch | arm / 64 | system | Yes | Any |
JavaScript | 32 | static | Yes | Any |
WebAssembly | 32 | static | Yes | Any |
iOS | arm64 | static | No | macOS |
iOS-Simulator | 64 | static | No | macOS |
AsteroidOS | arm | system | No | Linux |
FreeBSD | 32 / 64 | system | No | FreeBSD |
License
This package is released under LGPLv3
Qt itself is licensed and available under multiple licenses.
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot