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
|
<html>
<head>
<script type="text/javascript" src="qrc:///qwebchannel/qwebchannel.js"></script>
<script type="text/javascript">
//BEGIN HELPER
function output(x) {
document.querySelector("#out").innerHTML += x + "\n";
}
function createLink(label, onclick) {
var link = document.createElement("a");
link.href = "#";
link.onclick = onclick
link.appendChild(document.createTextNode(label));
return link;
}
function addObject(object) {
object.timeout.connect(function() { output('timeout of object ' + object.objectName()); });
object.sig1.connect(function(a, b, c) {
output('sig1 of object ' + object.objectName() + ": a = " + a + ", b = " + b + ", c = " + c);
});
object.sig2.connect(function() { output('sig2 of object ' + object.objectName()); });
object.prop1Changed.connect(function() {
// note: notify signal doesn't have the new value, so you must use direct access
output("prop1 of object " + object.objectName() + " changed, direct: " + object.prop1());
});
object.prop2Changed.connect(function(newVal) {
output("prop2 of object " + object.objectName() + " changed, new val: " + newVal + ", direct: " + object.prop2());
});
object.destroyed.connect(function() {
output("object destroyed " + object.objectName());
});
var container = document.getElementById("objects");
var element = document.createElement("p");
element.appendChild(document.createTextNode(object.objectName() + ":"));
element.appendChild(createLink("debugMe", function() {
object.debugMe('Debugging!', function(result) { output(result); });
}));
element.appendChild(createLink("manyArgs", function() {
object.manyArgs(1, 0.5, 'asdf', function(result) { output(result); });
}));
element.appendChild(createLink("get prop1", function() {
output(object.prop1());
}));
element.appendChild(createLink("set prop1", function() {
object.prop1 = "Set prop1 on " + (new Date());
}));
element.appendChild(createLink("get prop2", function() {
output(object.prop2());
}));
element.appendChild(createLink("set prop2", function() {
object.prop2 = "Set prop2 on " + (new Date());
}));
element.appendChild(createLink("start timer", function() {
object.startTimer(1000);
}));
element.appendChild(createLink("delete", function() {
object.deleteLater();
}));
container.appendChild(element);
}
var createdObjects = 0;
function createObject() {
testObjectFactory.createObject("myObj" + (createdObjects++), function(createdObject) {
addObject(createdObject);
});
}
//END HELPER
//BEGIN SETUP
var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]);
new QWebChannel(baseUrl, function(channel) {
// do stuff with registered QObjects
addObject(initialTestObject);
});
//END SETUP
</script>
<style type="text/css">
#objects a {
margin: 0 10px;
}
</style>
</head>
<body>
<div id="objects"></div>
<br/>
<a href="#" onclick="createObject()">Create New Object</a>. Note: Only created objects can be deleted, the initial object will stay.<br/>
<textarea id="out" style="height:80%; width: 80%"></textarea>
</body>
</html>
|