Important: Please read the Qt Code of Conduct -

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):
            self.client = QtWebSockets.QWebSocket('', QtWebSockets.QWebSocketProtocol.Version13, None)
            self.hostAdr = kwargs['host']
        def do_ping(self):
            print('client: ping')
        def onPong(self, elapsedTime, payload):
            print('onPong - time: {} ; payload: {}'.format(elapsedTime, payload))
        def Connect(self):
        def sendMessage(self, bName, bValue):
            self.client.sendTextMessage('{"' + bName + '": "' + str(bValue) + '"}')
        def sendMessage2(self, bValue):
        def close(self):

    anyone who can help me? :)

  • @Kris-Revi
    Since there isn't any answer other than just do the conversion, using docs as necessary, may I ask: if you are familiar/comfortable with Python but not with C++, why are you trying to do this conversion?

  • @JonB 2 reasons

    1. Native Qt C++ is faster
    2. Making a .exe from PyQt5 Python is a pain (many people have said to me that i should just convert it to C++)

  • @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.

  • @eyllanesc

    and i quote

    but im lacking a good tutorial

  • @Kris-Revi There is no such magic tutorial, the closest are the official examples:

  • @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)


  • @Kris-Revi That is a linking problem, check if the Qt you have installed has the QtWebsockets module installed. Also show your .pro.

  • @eyllanesc i fixed it by adding

    QT += websockets 

    to the .pro

    but im getting this now

    00:00:44: Cannot retrieve debugging output.

Log in to reply