Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Sender always is null(Invalid Signal signature: textMessageReceived(str))

    Qt for Python
    4
    5
    951
    Loading More Posts
    • 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.
    • tham
      tham last edited by tham

      OS : win10 64bits
      python : 3.7.3(anaconda)
      install by pip : pip install PySide2(PySide2 5.12.2)
      llvm: libclang-release_70-based-windows-mingw_64\libclang

      I am trying to find out the sender(find out which QWebSocket send the message), but it always tell me the sender is None, try to follow the suggestion in this post, use different way to connect signal and slot, but it always give me error message "Invalid Signal signature: textMessageReceived(str)".

      Minimum codes to reproduce:

      import sys
      
      from PySide2.QtCore import Slot, SIGNAL
      from PySide2.QtNetwork import QHostAddress
      from PySide2.QtWidgets import QApplication, QPushButton
      from PySide2.QtWebSockets import QWebSocketServer, QWebSocket
      
      
      class Worker(QPushButton):
      
          def __init__(self):
              super(Worker, self).__init__()
      
              self.clicked.connect(self.run)
              self.__server = QWebSocketServer("sss", QWebSocketServer.NonSecureMode)
              if self.__server.listen(QHostAddress.AnyIPv4, 1234):
                  print("server listening")
                  self.__server.newConnection.connect(self.__clientConnected)
              self.__socket = QWebSocket()
              print("socket open")
              self.__socket.open("ws://localhost:1234")
      
          def __connect(self):
              self.__socket.open("ws//127.0.0.1:1234")
      
          def __clientConnected(self):
              print("client connected sender:", self.sender())  # this sender is not null
              clientConnected = self.__server.nextPendingConnection()
      
              # connect by this solutoin, the sender always is null
              clientConnected.textMessageReceived.connect(self.__textMessageReceived)
      
              # connect by SIGNAL always tell me Invalid Signal signature: textMessageReceived(str)
              clientConnected.connect(clientConnected, SIGNAL("textMessageReceived(str)"), self.__textMessageReceived)
      
          @Slot()
          def run(self):
              print("run sender:", self.sender())  # this sender is not null
              self.__socket.sendTextMessage("send message")
      
          @Slot(str)
          def __textMessageReceived(self, msg):  # this sender always is null
              print("text message sender:", self.sender())
      
      
      if __name__ == "__main__":
          app = QApplication(sys.argv)
      
          worker = Worker()
          worker.setText("click me")
          worker.resize(640, 480)
          worker.show()
      
          sys.exit(app.exec_())
      

      I try to import QString, but cannot do it
      Do anyone know how to solve it?Thanks

      1 Reply Last reply Reply Quote 0
      • Kent-Dorfman
        Kent-Dorfman last edited by

        I think you are trying to be too slick, implementing network code under a pushbutton. Separate out the functionality into different objects and communicate between them when necessary.

        tham 1 Reply Last reply Reply Quote 0
        • tham
          tham @Kent-Dorfman last edited by

          @Kent-Dorfman Thanks, this is just a minimum example to show the issues, do you know how could I solve the issue of "Sender is None"? Thanks

          1 Reply Last reply Reply Quote 0
          • K
            klyjm last edited by

            Remove the @Slot(), I had the same question, and I remove the @Slot(), everything is ok.

            1 Reply Last reply Reply Quote 0
            • Denni 0
              Denni 0 Banned last edited by Denni 0

              Okay removing @Slot() means you are not using Signal/Slots and will be making a direct function call. The question I pose is what are you trying to implement with your version of this as I realize this is just an MRE of problem you are experiencing.

              As a reference without seeing the rest I am going to guess you might be confusing things. Sockets are different than Signal/Slots as Sockets are mainly for internet communication and Signal/Slots are for internal code communication mainly between Threads. So are you attempting internet communication or internal (to the application) code communication?

              If the latter then I can help you sort out how to properly use Signal/Slots if the former I will have to pass as I have not delved into Sockets yet.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post