<div dir="ltr">Anton, thank you very much for clarification!<div class="gmail_extra"><br clear="all"><div><div>Best Regards,</div></div><div>Pavel Vasev</div><div><br></div>
<br><div class="gmail_quote">2015-03-03 12:38 GMT+05:00 Anton Kreuzkamp <span dir="ltr"><<a href="mailto:akreuzkamp@web.de" target="_blank">akreuzkamp@web.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
yes, QtWebChannel is supposed to do client-server-communication. Currently it<br>
only works with a C++/Qt based server (which I use in a personal project). But<br>
theoretically (and that's the goal after all) it's possible to do the<br>
communication between a nodejs/php/JavaEE/... server and a qmlweb client using<br>
QtWebChannel (that's possible, as soon as someone implements the server side<br>
of the protocol for those server-technologies).<br>
<br>
To use it on client side:<br>
<span><br>
1. include qwebchannel.js into your index.html:<br>
<script type="text/javascript" src="qmlweb/src/qwebchannel.js"></script><br>
<br>
2. instanciate a websocket and a webchannel in your js-code:<br>
<br>
var socket = new WebSocket('<a href="http://example.com:8080/myWebSocketServer'" target="_blank">example.com:8080/myWebSocketServer'</a>);<br>
var myObj;<br>
<br>
socket.onclose = function() {<br>
console.log("web channel closed.");<br>
};<br>
socket.onerror = function(error) {<br>
console.error("web channel error: " + error);<br>
};<br>
socket.onopen = function() {<br>
new QWebChannel(socket, function(channel) {<br>
// Stuff we do when the remote object arrives.<br>
myObj = channel.objects.myObj;<br>
myObj.someSignal.connect(function(someArg) {<br>
//...<br>
});<br>
});<br>
}<br>
<br>
3. In Qml do whatever you want with it (you can just access your object using<br>
myObj). But attention: You always have to handle the case, the object is not<br>
yet there. Alternatively you can create the QML scene just when the object<br>
arrived.<br>
I plan to implement QMLEngine.registerSingleton(), though, which would then<br>
wait for the channel to be ready, synchronously.<br>
<br>
<br>
</span>4. For the (C++/Qt-) server side you need (e.g. in your main()):<br>
<br>
QWebChannel channel;<br>
QWebSocketServer server("QWebChannel Standalone Example Server",<br>
QWebSocketServer::NonSecureMode);<br>
if (!server.listen(QHostAddress::Any, 10002)) {<br>
qFatal("Failed to open web socket server.");<br>
return 1;<br>
}<br>
<br>
MyObj myObj;<br>
<br>
QObject::connect(&server, &QWebSocketServer::newConnection, [&] () {<br>
channel.connectTo(new WebSocketTransport(server.nextPendingConnection()));<br>
// Do some init stuff...<br>
});<br>
<br>
channel.registerObject("myObj", &myObj);<br>
<br>
Cheers, Anton<br>
<span><br>
<br>
On Monday 02 March 2015 21:00:47 you wrote:<br>
</span><div><div>> Anton, hi again!! ;-)<br>
><br>
> I noted that you made some deeds on QtWebChannel thing.<br>
><br>
> Could you please describe, how could it be used?<br>
><br>
> I googled some info and found<br>
> <a href="http://www.kdab.com/qt-webchannel-bridging-gap-cqml-web/" target="_blank">http://www.kdab.com/qt-webchannel-bridging-gap-cqml-web/</a><br>
> but I cannot understand, if we are already in browser, how<br>
> do you consider to use QtWebChannel?<br>
><br>
> Can it be used for browser-server communication?<br>
><br>
> e.g. can I load some qml objects in nodejs and communicate<br>
> with browser using QtWebChannel?<br>
><br>
> Best Regards,<br>
> Pavel Vasev<br>
<br>
</div></div><div><div>--<br>
Gruß auch an die NSA.</div></div></blockquote></div><br></div></div>