Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Does QWebSocketServer class store all QWebSocket objects?

Does QWebSocketServer class store all QWebSocket objects?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 251 Views
  • 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.
  • mmjvoxM Offline
    mmjvoxM Offline
    mmjvox
    wrote on last edited by mmjvox
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • mmjvoxM 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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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);
      
      mmjvoxM 1 Reply Last reply
      0
      • JonBJ JonB

        @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);
        
        mmjvoxM Offline
        mmjvoxM Offline
        mmjvox
        wrote on last edited by
        #3

        @JonB
        Thank you.

        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