forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customtype.go
48 lines (38 loc) · 796 Bytes
/
customtype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"os"
"gopkg.in/qml.v1"
)
func main() {
if err := qml.Run(run); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
type GoType struct {
Text string
}
func (v *GoType) SetText(text string) {
fmt.Println("Text changing to:", text)
v.Text = text
}
type GoSingleton struct {
Event string
}
func run() error {
qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
Init: func(v *GoType, obj qml.Object) {},
}, {
Init: func(v *GoSingleton, obj qml.Object) { v.Event = "birthday" },
Singleton: true,
}})
engine := qml.NewEngine()
component, err := engine.LoadFile("customtype.qml")
if err != nil {
return err
}
value := component.Create(nil)
fmt.Println("Text is:", value.Interface().(*GoType).Text)
return nil
}