Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Sender always is null(Invalid Signal signature: textMessageReceived(str))

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

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 4 Posters 1.9k Views 1 Watching
  • 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.
  • thamT Offline
    thamT Offline
    tham
    wrote on last edited by tham
    #1

    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
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      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.

      If you meet the AI on the road, kill it.

      thamT 1 Reply Last reply
      0
      • Kent-DorfmanK Kent-Dorfman

        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.

        thamT Offline
        thamT Offline
        tham
        wrote on last edited by
        #3

        @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
        0
        • K Offline
          K Offline
          klyjm
          wrote on last edited by
          #4

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

          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