Qt Forum

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

    Solved Does QWebSocketServer class store all QWebSocket objects?

    General and Desktop
    2
    3
    86
    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.
    • mmjvox
      mmjvox last edited by mmjvox

      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?

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @mmjvox last edited by

        @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);
        
        mmjvox 1 Reply Last reply Reply Quote 0
        • mmjvox
          mmjvox @JonB last edited by

          @JonB
          Thank you.

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