Sender always is null(Invalid Signal signature: textMessageReceived(str))
-
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\libclangI 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 -
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.
-
@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