Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Converting PyQt5 (Python) to Qt C++ QtWebSockets
QtWS25 Last Chance

Converting PyQt5 (Python) to Qt C++ QtWebSockets

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kris Revi
    wrote on last edited by
    #1

    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? :)

    JonBJ 1 Reply Last reply
    -1
    • K Kris Revi

      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? :)

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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?

      K 1 Reply Last reply
      0
      • JonBJ JonB

        @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?

        K Offline
        K Offline
        Kris Revi
        wrote on last edited by
        #3

        @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++)
        1 Reply Last reply
        0
        • eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #4

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

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          K 1 Reply Last reply
          0
          • eyllanescE eyllanesc

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

            K Offline
            K Offline
            Kris Revi
            wrote on last edited by
            #5

            @eyllanesc

            and i quote

            but im lacking a good tutorial
            
            eyllanescE 1 Reply Last reply
            0
            • K Kris Revi

              @eyllanesc

              and i quote

              but im lacking a good tutorial
              
              eyllanescE Offline
              eyllanescE Offline
              eyllanesc
              wrote on last edited by
              #6

              @Kris-Revi There is no such magic tutorial, the closest are the official examples: https://doc.qt.io/qt-5/qtwebsockets-examples.html

              If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

              K 1 Reply Last reply
              0
              • eyllanescE eyllanesc

                @Kris-Revi There is no such magic tutorial, the closest are the official examples: https://doc.qt.io/qt-5/qtwebsockets-examples.html

                K Offline
                K Offline
                Kris Revi
                wrote on last edited by Kris Revi
                #7

                @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
                Errors

                eyllanescE 1 Reply Last reply
                0
                • K Kris Revi

                  @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
                  Errors

                  eyllanescE Offline
                  eyllanescE Offline
                  eyllanesc
                  wrote on last edited by
                  #8

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

                  If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                  K 1 Reply Last reply
                  0
                  • eyllanescE eyllanesc

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

                    K Offline
                    K Offline
                    Kris Revi
                    wrote on last edited by
                    #9

                    @eyllanesc i fixed it by adding

                    QT += websockets 
                    

                    to the .pro

                    but im getting this now

                    00:00:44: Cannot retrieve debugging output.
                    
                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved