summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-10-31 16:14:28 +0100
committerPierre Rossi <pierre.rossi@gmail.com>2013-11-01 13:57:52 +0100
commita607c948860782b5a095fe802f3acdd5aaf6a568 (patch)
tree8fbd8bd773acfa7fe438fe95af2588485d8e4269 /examples
parent708c0dd39d9f2a6f7d699364c6991d78bd30f9a8 (diff)
downloadqtwebchannel-a607c948860782b5a095fe802f3acdd5aaf6a568.tar.gz
Greatly optimize WebChannel in various ways.
This is a big code drop - sorry for that. The benefits are worth it though, I'm sure. The optimizations were required to make the WebChannel useable even on a low-end embedded device with medium amount of traffic. The changes in this patch can be grouped into different parts: a) Do more in C++: Esp. by leveraging e.g. the new classInfoForObjects in QtMetaObjectPublisher (on the C++ side) one can greatly reduce the time required for initialization of the webchannel. b) Property Caching: Instead of requiring a socket roundtrip whenever a property is read on the HTML side, we now cache the property values on the HTML side. Note that for this to work properly, one needs to add proper notify signals to the property declarations, as otherwise the cache will not get updated. c) Grouping: Instead of sending separate messages to the clients for every property update, these signals are grouped by a 50ms timer, and then send aggregated to the client. This reduces the socket traffic, as more boiler plate can be shared. d) Compression: Some data was previously send repeatedly, such as property name and notify signal. This is now compressed internally where possible (i.e. for the ${propName}Changed naming scheme). e) Message Flood Prevention: Previously, one could easily flood an HTML client by sending data to it. If it could not work off the incoming stream one would freeze the HTML client. Now, we wait for an idle signal of the client prior to sending new data to it. Paired with the message grouping and property cache mentioned above, we are able to only send the newest data once the HTML client becomes active again. I.e. we discard now-obsolete property updates etc. Change-Id: I8f3ae16ed6c1f6a89b644acdce7efbf0f07fc786 Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qtobject/qml/qtobject/main.qml1
-rw-r--r--examples/qtobject/testobject.cpp2
-rw-r--r--examples/qtobject/testobject.h6
3 files changed, 7 insertions, 2 deletions
diff --git a/examples/qtobject/qml/qtobject/main.qml b/examples/qtobject/qml/qtobject/main.qml
index 7a63cd2..d00c9ac 100644
--- a/examples/qtobject/qml/qtobject/main.qml
+++ b/examples/qtobject/qml/qtobject/main.qml
@@ -49,6 +49,7 @@ import QtWebKit.experimental 1.0
Rectangle {
MetaObjectPublisher {
id: publisher
+ webChannel: webChannel
}
TestObject {
diff --git a/examples/qtobject/testobject.cpp b/examples/qtobject/testobject.cpp
index 4bcd92f..e18dbc0 100644
--- a/examples/qtobject/testobject.cpp
+++ b/examples/qtobject/testobject.cpp
@@ -18,6 +18,7 @@ void TestObject::setProp1(const QString& s)
p1 = s;
qWarning() << __func__ << p1;
emit sig1(1, 0.5, QStringLiteral("asdf"));
+ emit prop1Changed();
}
void TestObject::setProp2(const QString& s)
@@ -25,6 +26,7 @@ void TestObject::setProp2(const QString& s)
p2 = s;
qWarning() << __func__ << p2;
emit sig2();
+ emit prop2Changed(s);
}
QString TestObject::manyArgs(int a, float b, const QString& c) const
diff --git a/examples/qtobject/testobject.h b/examples/qtobject/testobject.h
index 39dc608..f3f1c03 100644
--- a/examples/qtobject/testobject.h
+++ b/examples/qtobject/testobject.h
@@ -7,8 +7,8 @@
class TestObject : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString prop1 READ prop1 WRITE setProp1)
- Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2)
+ Q_PROPERTY(QString prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
+ Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed)
public:
explicit TestObject(QObject *parent = 0);
QString prop1() const { return "p1" + p1 + objectName(); }
@@ -21,6 +21,8 @@ signals:
void timeout();
void sig1(int a, float b, const QString& c);
void sig2();
+ void prop1Changed();
+ void prop2Changed(const QString& newValue);
public slots:
void startTimer(int millis)