title: Can i use QTcpSocket again for another connection after deleteLater?
body: <p>I try to use <code>QTcpSserver</code>, which would keep connection with <strong>one and only one client</strong> at a time, until the client disconnects. So, I keep the client with a member pointer in my class.</p>
  
  <p>The problem arises here: In the examples I see on the internet, after <code>disconnected()</code>, it is called <code>deleteLater()</code>. Good, but I would use this class-member pointer again for another connection. Remember that the server keeps one and only one client at a time. So, what if the socket object is deleted after another connection assigned on it?</p>
  
  <p>What I mean is:</p>
  
  <pre><code>class TcpServer(QObject* o) : public QTcpServer {
  ...
  private:
      QTcpSocket* client;
  }
  
  void TcpServer::connected() {
      client = this-&gt;nextPendingConnection();
      this-&gt;pauseAccepting();
      connect(client, SIGNAL(disconnected()), client, SLOT(clientDisconnected()));
  }
  
  void TcpServer::clientDisconnected() {
      client-&gt;deleteLater();
      this-&gt;resumeAccepting();
  }
  </code></pre>
  
  <p>Scenario is this:</p>
  
  <ol>
  <li><p>Client connected. So, <code>client = nextPendingConnection();</code></p></li>
  <li><p>Server paused listening. Does not accept new connection.</p></li>
  <li><p>Client is disconnected. <code>client</code> needs to be released. So, <code>client-&gt;deleteLater()</code> is calleed.</p></li>
  <li><p>Server continues listening.</p></li>
  <li><p>New connection comes. So, I need to <code>client = nextPendingConnection();</code></p></li>
  </ol>
  
  <p><strong>But</strong>, previous <code>client</code> object was deleted? Maybe? Maybe not? What if event loop tries to delete <code>client</code>, after I have assigned the new connection to it in step 5?</p>
  
  <p>So, how would I keep one and only one client, while deleting previous disconnected ones?</p>
  
  <p>Would it be safe if I do this?</p>
  
  <pre><code>void TcpServer::clientDisconnected()
  {
      QSocket* ptr = client;
      ptr-&gt;deleteLater();
      ...
  }
  </code></pre>