forked from therecipe/qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_world2.go
76 lines (58 loc) · 1.71 KB
/
hello_world2.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"os"
"github.com/akiyosi/qt/core"
"github.com/akiyosi/qt/gui"
"github.com/akiyosi/qt/quick"
)
type HelloClientRPC struct {
core.QObject
_ func(string) `slot:"sayHello"`
_ func() `slot:"shutdown"`
}
type HelloClientFactory struct {
core.QObject
_ func(msg string) `signal:"info"`
_ func(err, msg string) `signal:"error"`
_ func(msg string) `signal:"success"`
_ func(addr string) *HelloClientRPC `slot:"newClient"`
}
func main() {
go serve()
core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
gui.NewQGuiApplication(len(os.Args), os.Args)
var view = quick.NewQQuickView(nil)
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
var helloClientFactory = NewHelloClientFactory(nil)
HelloClientRPC_QRegisterMetaType() //needed to register HelloClientRPC* as a return struct for QML
helloClientFactory.ConnectNewClient(func(addr string) *HelloClientRPC {
var (
client, err = New(addr)
ret = NewHelloClientRPC(nil)
)
helloClientFactory.Info("Trying " + addr + "\n")
if err != nil {
helloClientFactory.Error("create client", err.Error())
return nil
}
ret.ConnectSayHello(func(s string) {
var out, err = client.SayHello(s)
if err != nil {
helloClientFactory.Error("receive response", err.Error())
return
}
helloClientFactory.Success(string(out))
})
ret.ConnectShutdown(func() {
var err = client.Shutdown()
if err != nil {
helloClientFactory.Error("shutdown client", err.Error())
}
})
return ret
})
view.RootContext().SetContextProperty("HelloClientFactory", helloClientFactory)
view.SetSource(core.NewQUrl3("qrc:/qml/hello_world2.qml", 0))
view.Show()
gui.QGuiApplication_Exec()
}