Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I integrate Javascript library (socketio) in QML?

After the C++ socketio library has failed me, I'm trying to use the JavaScript library in QT's QML. I copied the client from https://cdn.socket.io/socket.io-1.4.5.js to socketio145.js.

When I import it as such:

.import "socketio145.js" as IO;

Running:

socket = IO.io();

Fails with the error "[error stack]Expected token :'\n" on the 3rd line of socketio145.js. Is this some non-qml compliant javascript code or is something else going on? I'm lost.

like image 920
nico Avatar asked Apr 07 '26 06:04

nico


1 Answers

I made something that solves the problem. I have not had any luck with this at all. I tried compiling SocketIO's C++ library into my project, tried including the JS. But nothing worked and libraries were just confused.

So I took the Qt QWebSocket and wrapped it in a warm and fuzzy coat that looks and works in qml very similarly to how SocketIO works in Javascript.

https://github.com/Dimcon/ParthanonsQWebSocketIO

It works on both Desktop and Android and all you have to do is copy the parthanonsQWebSocket.h file into your project and add in the class to your QML. More details on the readme.

I hope this helps you guys from struggling with this issue the way I did :( :)

like image 107
Parthanon Avatar answered Apr 09 '26 18:04

Parthanon