-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.qml
More file actions
118 lines (100 loc) · 3.95 KB
/
main.qml
File metadata and controls
118 lines (100 loc) · 3.95 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import QtQuick 2.7
import QtQuick.Window 2.2
import Redis 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
MainForm {
id: form
anchors.fill: parent
btnPublishEvent1.onClicked: redis.publishedSignal1()
btnPublishEvent2.onClicked: redis.publishedSignal2()
btnGetAsync.onClicked: {
redis.get("get:async", function(value){
redis.asynchronousGetVariable = value;
})
}
btnGetSync.onClicked: {
redis.synchronousGetVariable = redis.get("get:sync");
}
btnSetRemoteDouble.onClicked: {
redis.set("remote:published:double", Math.random());
}
btnSetRemoteString.onClicked: {
redis.set("remote:published:string", Math.random().toString(36).substring(7));
}
btnClearAll.onClicked: {
redis.localPublishedDouble = 0.0;
redis.localPublishedString = ".";
redis.localSubscribedDouble = 0.0;
redis.localSubscribedString = "";
redis.synchronousGetVariable = "";
redis.asynchronousGetVariable = "";
}
}
RedisInterface {
id: redis
serverUrl: "http://localhost:7379/"
width: 800
height: 600
property double localSubscribedDouble
property string localSubscribedString
property double localPublishedDouble: 0.00
property string localPublishedString: "."
property string asynchronousGetVariable: ""
property string synchronousGetVariable: ""
signal publishedSignal1
signal publishedSignal2
signal localSignal
onLocalSignal: handleLocalSignal();
function localMethod() {
console.log("(QML) localMethod() called");
}
function localWildcard() {
console.log("(QML) localWildcard() called");
}
function handleLocalSignal() {
console.log("(QML) localSignal() emitted and handled by handleLocalSignal()");
}
Component.onCompleted: init();
subscribedProperties: [
{ remote: "remote:published:double", local: "localSubscribedDouble" },
{ remote: "remote:published:string", local: "localSubscribedString" }
]
publishedProperties: [
{ local: "localPublishedDouble", remote: "remote:subscribed:double" },
{ local: "localPublishedString", remote: "remote:subscribed:string" }
]
subscribedEvents: [
{ remote: "remote:signal:trigger", local: "localSignal" },
{ remote: "remote:method:trigger", local: "localMethod" },
{ remote: "remote:wildcard*", local: "localWildcard" }
]
publishedEvents: [
{ local: "publishedSignal1", remote: "remote:subscribed:event1" },
{ local: "publishedSignal2", remote: "remote:subscribed:event2" }
]
Text {
anchors.centerIn: parent
text: "remote:published:double : " + redis.localSubscribedDouble.toFixed(20) + "\n" +
"remote:published:string : \"" + redis.localSubscribedString + "\"\n" +
"localPublishedDouble : " + redis.localPublishedDouble.toFixed(2) + "\n" +
"localPublishedString : \"" + redis.localPublishedString + "\"\n" +
"get:async : \"" + redis.asynchronousGetVariable + "\"\n" +
"get:sync : \"" + redis.synchronousGetVariable + "\""
}
Timer {
running: true
repeat: true
interval: 16
onTriggered: {
redis.localPublishedDouble += 0.1;
redis.localPublishedString += ".";
if(redis.localPublishedString.length > 10)
redis.localPublishedString = ".";
}
}
}
}