Convert Figma logo to code with AI

go-qml logoqml

QML support for the Go language

1,955
187
1,955
66

Top Related Projects

10,376

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly

The android-go project provides a platform for writing native Android apps in Go programming language.

1,477

Golang bindings to the Qt cross-platform application framework.

Quick Overview

go-qml/qml is a QML library for the Go programming language. It allows developers to create graphical user interfaces using QML (Qt Modeling Language) within Go applications, bridging the gap between Go's backend capabilities and Qt's rich UI framework.

Pros

  • Enables creation of cross-platform GUI applications using Go and QML
  • Provides seamless integration between Go's backend and QML's frontend
  • Leverages the power and flexibility of QML for UI design
  • Allows for rapid prototyping and development of desktop applications

Cons

  • Limited community support compared to more mainstream GUI frameworks
  • Requires knowledge of both Go and QML, which may increase the learning curve
  • Dependency on Qt libraries, which can increase application size
  • May have performance overhead due to bridging between Go and QML

Code Examples

  1. Creating a simple QML window:
package main

import (
    "fmt"
    "gopkg.in/qml.v1"
    "os"
)

func main() {
    if err := qml.Run(run); err != nil {
        fmt.Fprintf(os.Stderr, "error: %v\n", err)
        os.Exit(1)
    }
}

func run() error {
    engine := qml.NewEngine()
    component, err := engine.LoadFile("main.qml")
    if err != nil {
        return err
    }

    win := component.CreateWindow(nil)
    win.Show()
    win.Wait()

    return nil
}
  1. Exposing Go functions to QML:
type Person struct {
    Name string
}

func (p *Person) SayHello() string {
    return "Hello, " + p.Name + "!"
}

func run() error {
    engine := qml.NewEngine()
    
    context := engine.Context()
    context.SetVar("person", &Person{Name: "Alice"})

    component, err := engine.LoadFile("main.qml")
    if err != nil {
        return err
    }

    win := component.CreateWindow(nil)
    win.Show()
    win.Wait()

    return nil
}
  1. Handling QML signals in Go:
func run() error {
    engine := qml.NewEngine()
    
    component, err := engine.LoadFile("main.qml")
    if err != nil {
        return err
    }

    win := component.CreateWindow(nil)

    win.On("buttonClicked", func(message string) {
        fmt.Println("Button clicked:", message)
    })

    win.Show()
    win.Wait()

    return nil
}

Getting Started

  1. Install Go and set up your Go environment.
  2. Install Qt 5.x and set up the necessary environment variables.
  3. Install go-qml:
    go get gopkg.in/qml.v1
    
  4. Create a new Go file (e.g., main.go) and a QML file (e.g., main.qml).
  5. Write your Go code to initialize the QML engine and load the QML file.
  6. Run your application:
    go run main.go
    

Competitor Comparisons

10,376

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly

Pros of qt

  • Broader Qt support: Covers more Qt modules beyond just QML
  • Active development: More recent updates and larger community
  • Cross-platform: Supports multiple operating systems and architectures

Cons of qt

  • Larger codebase: More complex and potentially harder to maintain
  • Steeper learning curve: Requires more knowledge of Qt internals
  • Slower build times: Due to its comprehensive nature

Code Comparison

qt:

func main() {
    app := widgets.NewQApplication(len(os.Args), os.Args)
    window := widgets.NewQMainWindow(nil, 0)
    window.SetWindowTitle("Hello Qt")
    window.Show()
    app.Exec()
}

qml:

func main() {
    qml.Run(run)
}

func run() error {
    engine := qml.NewEngine()
    component, err := engine.LoadFile("main.qml")
    if err != nil {
        return err
    }
    win := component.CreateWindow(nil)
    win.Show()
    win.Wait()
    return nil
}

The qt example demonstrates creating a basic Qt widget application, while the qml example focuses on loading and running a QML file. qt provides a more comprehensive approach to Qt development in Go, while qml specializes in QML integration.

The android-go project provides a platform for writing native Android apps in Go programming language.

Pros of android-go

  • Focuses specifically on Android development with Go
  • Provides tools for building and packaging Android apps with Go
  • Includes Android-specific bindings and utilities

Cons of android-go

  • Limited to Android platform, less versatile than qml
  • Smaller community and fewer resources compared to qml
  • May require more Android-specific knowledge

Code Comparison

android-go example:

package main

import "golang.org/x/mobile/app"

func main() {
    app.Main(func(a app.App) {
        // Android app logic here
    })
}

qml example:

package main

import (
    "gopkg.in/qml.v1"
)

func main() {
    qml.Run(func() error {
        engine := qml.NewEngine()
        component, err := engine.LoadFile("main.qml")
        // QML app logic here
    })
}

The android-go code focuses on Android-specific app structure, while qml uses QML for cross-platform UI development. android-go is more tailored for Android, whereas qml offers broader platform support but requires QML knowledge.

1,477

Golang bindings to the Qt cross-platform application framework.

Pros of goqt

  • Supports both Qt5 and Qt6, offering more flexibility and future-proofing
  • Provides a more comprehensive set of Qt bindings, covering a wider range of Qt modules
  • Actively maintained with more recent updates and contributions

Cons of goqt

  • Steeper learning curve due to more extensive API coverage
  • Potentially larger binary size and memory footprint due to broader Qt support
  • May require more setup and configuration compared to qml's simpler approach

Code Comparison

qml:

import "gopkg.in/qml.v1"

func main() {
    engine := qml.NewEngine()
    component, err := engine.LoadFile("view.qml")
    window := component.CreateWindow(nil)
    window.Show()
}

goqt:

import "github.com/kitech/qt.go/qtwidgets"

func main() {
    app := qtwidgets.NewQApplication(0, nil)
    window := qtwidgets.NewQMainWindow(nil, 0)
    window.Show()
    app.Exec()
}

The code comparison shows that qml focuses on QML-based UI development, while goqt provides a more traditional Qt widgets approach. goqt offers more flexibility in terms of UI development paradigms, but may require more verbose code for simple applications compared to qml's concise QML-centric approach.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

QML support for the Go language

Documentation

The introductory documentation as well as the detailed API documentation is available at gopkg.in/qml.v1.

Blog posts

Some relevant blog posts:

Videos

These introductory videos demonstrate the use of Go QML:

Community

Please join the mailing list for following relevant development news and discussing project details.

Installation

To try the alpha release you'll need:

  • Go >= 1.2, for the C++ support of go build
  • Qt 5.0.X or 5.1.X with the development files
  • The Qt headers qmetaobject_p.h and qmetaobjectbuilder_p.h, for the dynamic meta object support

See below for more details about getting these requirements installed in different environments and operating systems.

After the requirements are satisfied, go get should work as usual:

go get gopkg.in/qml.v1

Requirements on Ubuntu

If you are using Ubuntu, the Ubuntu SDK will take care of the Qt dependencies:

$ sudo add-apt-repository ppa:ubuntu-sdk-team/ppa
$ sudo apt-get update
$ sudo apt-get install qtdeclarative5-dev qtbase5-private-dev qtdeclarative5-private-dev libqt5opengl5-dev qtdeclarative5-qtquick2-plugin

and Go >= 1.2 may be installed using godeb:

$ # Pick the right one for your system: 386 or amd64
$ ARCH=amd64
$ wget -q https://godeb.s3.amazonaws.com/godeb-$ARCH.tar.gz
$ tar xzvf godeb-$ARCH.tar.gz
godeb
$ sudo mv godeb /usr/local/bin
$ godeb install
$ go get gopkg.in/qml.v1

Requirements on Ubuntu Touch

After following the installation instructions for Ubuntu Touch, run the following commands to get a working build environment inside the device:

$ adb shell
# cd /tmp
# wget https://github.com/go-qml/qml/raw/v1/cmd/ubuntu-touch/setup.sh
# /bin/bash setup.sh
# su - phablet
$

At the end of setup.sh, the phablet user will have GOPATH=$HOME in the environment, the qml package will be built, and the particle example will be built and run. For stopping it from the command line, run as the phablet user:

$ ubuntu-app-stop gopkg.in.qml.particle-example

for running it again:

$ ubuntu-app-launch gopkg.in.qml.particle-example

These commands depend on the following file, installed by setup.sh:

~/.local/share/applications/gopkg.in.qml.particle-example.desktop

Requirements on Mac OS X

On Mac OS X you'll need QT5. It's easiest to install with Homebrew, a third-party package management system for OS X.

Installation instructions for Homebrew are here:

http://brew.sh/

Then, install the qt5 and pkg-config packages:

$ brew install qt5 pkg-config

Then, force brew to "link" qt5 (this makes it available under /usr/local):

$ brew link --force qt5

And finally, fetch and install go-qml:

$ go get gopkg.in/qml.v1

Requirements on Windows

On Windows you'll need the following:

Then, assuming Qt was installed under C:\Qt5.1.1\, set up the following environment variables in the respective configuration:

CPATH += C:\Qt5.1.1\5.1.1\mingw48_32\include
LIBRARY_PATH += C:\Qt5.1.1\5.1.1\mingw48_32\lib
PATH += C:\Qt5.1.1\5.1.1\mingw48_32\bin

After reopening the shell for the environment changes to take effect, this should work:

go get gopkg.in/qml.v1

Requirements everywhere else

If your operating system does not offer these dependencies readily, you may still have success installing Go >= 1.2 and Qt 5.0.2 directly from the upstreams. Note that you'll likely have to adapt environment variables to reflect the custom installation path for these libraries. See the instructions above for examples.