Converting PyQt5 (Python) to Qt C++ QtWebSockets
-
so i made a sketch / demo in PyQt5 and now im converting it to Native Qt C++
but im lacking a good tutorial on it so i can convert my python code
from PyQt5 import QtCore, QtWebSockets, QtNetwork from PyQt5.QtCore import QUrl, pyqtSignal class Socket(QtCore.QObject): error = pyqtSignal(QtNetwork.QAbstractSocket.SocketError) pingError = pyqtSignal(QtNetwork.QAbstractSocket.SocketError) connReady = pyqtSignal() def __init__(self, *args, **kwargs): QtCore.QObject.__init__(self) self.client = QtWebSockets.QWebSocket('', QtWebSockets.QWebSocketProtocol.Version13, None) self.client.error.connect(self.error) self.client.error.connect(self.pingError) self.client.connected.connect(self.connReady) self.hostAdr = kwargs['host'] def do_ping(self): print('client: ping') self.client.ping(b'ping') def onPong(self, elapsedTime, payload): print('onPong - time: {} ; payload: {}'.format(elapsedTime, payload)) def Connect(self): self.client.open(QUrl(f"ws://{self.hostAdr}:80")) self.client.pong.connect(self.onPong) def sendMessage(self, bName, bValue): self.client.sendTextMessage('{"' + bName + '": "' + str(bValue) + '"}') def sendMessage2(self, bValue): self.client.sendTextMessage(str(bValue)) def close(self): self.client.close()
anyone who can help me? :)
-
@Kris-Revi Converting a code to a language is not trivial (in general) so there will not be a tutorial that indicates what you are looking for. On the other hand, I don't see any attempt from you so it discourages me from trying to help you.
My recommendations is:
- Learn C ++,
- Learn Qt,
- Check the Qt examples with websockets,
- Try something to solve your problem, etc.
If you can't do the above then hire someone who has already done the above and then translate your code.
Your post seems to say: can you do my work for free?
I don't see any specific problem.
-
@Kris-Revi There is no such magic tutorial, the closest are the official examples: https://doc.qt.io/qt-5/qtwebsockets-examples.html
-
@eyllanesc i did follow the example on the docs just to test it out but im getting a shit load of errors for some reason :S i've copied JUST like it is in the example just to see it working (connecting to my ESP32)
Image