Socket
Socket
Sign inDemoInstall

github.com/sjb/qml

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/sjb/qml

Package qml offers graphical QML application support for the Go language. This package is in an alpha stage, and still in heavy development. APIs may change, and things may break. At this time contributors and developers that are interested in tracking the development closely are encouraged to use it. If you'd prefer a more stable release, please hold on a bit and subscribe to the mailing list for news. It's in a pretty good state, so it shall not take too long. See http://github.com/go-qml/qml for details. The qml package enables Go programs to display and manipulate graphical content using Qt's QML framework. QML uses a declarative language to express structure and style, and supports JavaScript for in-place manipulation of the described content. When using the Go qml package, such QML content can also interact with Go values, making use of its exported fields and methods, and even explicitly creating new instances of registered Go types. A simple Go application that integrates with QML may perform the following steps for offering a graphical interface: Some of these topics are covered below, and may also be observed in practice in the following examples: The following logic demonstrates loading a QML file into a window: Any QML object may be manipulated by Go via the Object interface. That interface is implemented both by dynamic QML values obtained from a running engine, and by Go types in the qml package that represent QML values, such as Window, Context, and Engine. For example, the following logic creates a window and prints its width whenever it's made visible: Information about the methods, properties, and signals that are available for QML objects may be obtained in the Qt documentation. As a reference, the "visibleChanged" signal and the "width" property used in the example above are described at: When in doubt about what type is being manipulated, the Object.TypeName method provides the type name of the underlying value. The simplest way of making a Go value available to QML code is setting it as a variable of the engine's root context, as in: This logic would enable the following QML code to successfully run: While registering an individual Go value as described above is a quick way to get started, it is also fairly limited. For more flexibility, a Go type may be registered so that QML code can natively create new instances in an arbitrary position of the structure. This may be achieved via the RegisterType function, as the following example demonstrates: With this logic in place, QML code can create new instances of Person by itself: Independently from the mechanism used to publish a Go value to QML code, its methods and fields are available to QML logic as methods and properties of the respective QML object representing it. As required by QML, though, the Go method and field names are lowercased according to the following scheme when being accesed from QML: While QML code can directly read and write exported fields of Go values, as described above, a Go type can also intercept writes to specific fields by declaring a setter method according to common Go conventions. This is often useful for updating the internal state or the visible content of a Go-defined type. For example: In the example above, whenever QML code attempts to update the Person.Name field via any means (direct assignment, object declarations, etc) the SetName method is invoked with the provided value instead. A setter method may also be used in conjunction with a getter method rather than a real type field. A method is only considered a getter in the presence of the respective setter, and according to common Go conventions it must not have the Get prefix. Inside QML logic, the getter and setter pair is seen as a single object property. Custom types implemented in Go may have displayable content by defining a Paint method such as: A simple example is available at: Resource files (qml code, images, etc) may be packed into the Go qml application binary to simplify its handling and distribution. This is done with the genqrc tool: The following blog post provides more details:


Version published

Readme

Source

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.

FAQs

Last updated on 09 Feb 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc