Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Does QWebSocketServer class store all QWebSocket objects?



  • I need to assign a key for each Web Socket that came from nextPendingConnection (QWebSocketServer class) for access them in future .
    Therefore i store QWebSocket objects in a map with a string key, it is ok and works

    but in this example:
    https://doc.qt.io/qt-5/echoserver.html
    in this function :

    echoServer::processTextMessage
    

    i saw this line:

    QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
    

    I wonder if​ does QWebSocketServer class store all QWebSocket objects in itself?
    And I mistakenly save them again in a map?



  • @mmjvox said in Does QWebSocketServer class store all QWebSocket objects?:

    I wonder if​ does QWebSocketServer class store all QWebSocket objects in itself and?

    I think not, or at least seemingly not accessible to you. https://doc.qt.io/qt-5/qwebsocketserver.html#nextPendingConnection

    Returns the next pending connection as a connected QWebSocket object. QWebSocketServer does not take ownership of the returned QWebSocket object. It is up to the caller to delete the object explicitly when it will no longer be used

    So you keep ownership of the QWebSockets.

    QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());

    That just gains access to the signal sender from the line

    connect(pSocket, &QWebSocket::textMessageReceived, this, &EchoServer::processTextMessage);
    


  • @JonB
    Thank you.


Log in to reply