summaryrefslogtreecommitdiff
path: root/examples/qtobject/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qtobject/index.html')
-rw-r--r--examples/qtobject/index.html92
1 files changed, 92 insertions, 0 deletions
diff --git a/examples/qtobject/index.html b/examples/qtobject/index.html
new file mode 100644
index 0000000..af2b940
--- /dev/null
+++ b/examples/qtobject/index.html
@@ -0,0 +1,92 @@
+<html>
+ <head>
+ <script type="text/javascript" src="qrc:///qwebchannel/webchannel.js"></script>
+ <script type="text/javascript" src="qrc:///qwebchannel/qobject.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) {
+ setupQObjectWebChannel(channel, function() {
+ // 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>