Skip to content

a high-level communication interface for github.com/therecipe/qt

License

Notifications You must be signed in to change notification settings

theMomax/hermes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hermes

A high-level communication interface for therecipe's awsome qt binding for Go. This package allows you to dynamically add Qml-Elements (from Qml-code as a string or file), set and read their properties and delete them.

Get Started

Go get this repository and let it generate the necessary files for Go to Qml connection:

go get github.com/hoffx/hermes
cd $GOPATH/src/github.com/hoffx/hermes
go generate

Integrate hermes into your Qml application on Go side by importing it and creating a new hermes.Controller:

// main.go
// Create application
app := gui.NewQGuiApplication(len(os.Args), os.Args)

// Create a QML application engine
engine := qml.NewQQmlApplicationEngine(nil)

hController = hermes.NewBridgeController(engine)
hController.AddEventListener("someEvent", someFunctionToCallAtEvent)
hController.AddEventListener("someEvent2", someFunctionToCallAtEvent2)

// Load the main qml file
window := qml.NewQQmlComponent5(engine, core.NewQUrl3("qml/main.qml", 0), nil)
root = window.Create(engine.RootContext())

// Execute app
gui.QGuiApplication_Exec()

Integrate hermes into your Qml application on Qml side by adding the code-snippet from hermes.qml to the ApplicationWindow element of your main.qml file:

import QtQuick 2.7
ApplicationWindow {
    id: window
    visible: true
    ...

    Connections
    {
        property var idMap: ({
            // -------------------------------------------
            // List all the ids here, you have to access
            // from Go. This is needed for
            // string to object mapping.
            // -------------------------------------------
            //window:window,
            //yourelement1:yourelement1
        })
        ...
    }

How to use it

On Go side it's easy. Just use your hController's functions. They aren't documented that bad... But make sure every qml element you want to access has been added to the idMap - manually by you (for the static part) or by the AddToQml function. Just read the documentation...

In Qml, use the hermes.sendToGo() command:

Button{
    id: yourButton
    onClicked: hermes.sendToGo("someEvent", "yourButton", '{ "extra_information_property": "extra_information_value" }')
}

You can use this project as a reference.

About

a high-level communication interface for github.com/therecipe/qt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published