title: QTcpSocket state always connected, even unplugging ethernet wire
body: <p>I have a QTcpSocket and I am reading into a loop. Each time a full packet has been read, or there has been an error, I manually check the status of the socket inside the loop, with:</p>
  
  <pre><code>    while(true){
      if(socket-&gt;state()==QAbstractSocket::ConnectedState){
          qDebug()&lt;&lt;"Socket status: connected. Looking for packets...";
          if(socket-&gt;waitForReadyRead(2000)){
          //...
      }
  </code></pre>
  
  <p>When I execute de program, once connected and the loop starts, it always prints <code>qDebug()&lt;&lt;"Socket status: connected. Looking for packets..."</code>; and then stucks at <code>waitForReadyRead</code> until some data is ready to be read.</p>
  
  <p>The problem is that disconnections are not detected. If I disconnect from network from the OS options, or even if I unplug the ethernet wire, it behaves the same: Socket state equals <code>QAbstractSocket::ConnectedStat</code>e, so it goes on, but without receiving anything of course.</p>
  
  <p>I also tried to detect disconnections connecting <code>disconnected()</code> signal (after fist connection) to a reconnect function:</p>
  
  <pre><code>// Detect disconnection in order to reconnect
      connect(socket, SIGNAL(disconnected()), this, SLOT(reconnect()));
  
  void MyClass::reconnect(){
      qDebug()&lt;&lt;"Signal DISCONNECTED emitted. Now trying to reconnect";
      panelGUI-&gt;mostrarValueOffline();
      socket-&gt;close();
      prepareSocket((Global::directionIPSerialServer).toLocal8Bit().data(), 8008, socket);
      qDebug()&lt;&lt;"Reconnected? Status: "&lt;&lt;socket-&gt;state();
  }
  </code></pre>
  
  <p>But signal is never emited, because this code is never executed. Which is logical, since it looks like socket state is always <code>ConnectedState</code>.</p>
  
  <p>If I plug again, connection is restored and starts to receive data again, but I do want to detect disconnections to show "Disconnected" at the GUI.</p>
  
  <p>Why is QTcpSocket behaving this way, and how can I solve this problem?</p>
  
  <p>EDIT: I'm creating socket at the class constructor, and then initialising calling prepareSocket function:</p>
  
  <pre><code>socket = new QTcpSocket();
  socket-&gt;moveToThread(this);
  
  bool prepareSocket(QString address, int port, QTcpSocket *socket) {
      socket-&gt;connectToHost(address, port);
      if(!socket-&gt;waitForConnected(2000)){
          qDebug()&lt;&lt;"Error creating socket: "&lt;&lt;socket-&gt;errorString();
          sleep(1);
          return false;
      }
      return true;
  }
  </code></pre>