Why QTcpSocket doesn't write ? I need to flush it to make it send my data
<p>I read in the documentation that to send a packet with QTcpSocket I can just use the <code>write</code> method.
But when I do it, my server doesn't receive it. I need to call <code>flush</code> or <code>waitForByteWritten</code> to send it.</p>

<pre><code>TCPClient::TCPClient(Client *babel , const std::string &amp;hostname, unsigned short port, QObject *parent) : QObject(parent), client(babel),  hostName(hostname), port(port), is_connected(false)
{
  this-&gt;tcpSocket = new QTcpSocket(this);
  connect(this-&gt;tcpSocket, SIGNAL(readyRead()),this, SLOT(readMessage()));
  connect(this-&gt;tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
  connect(this-&gt;tcpSocket, SIGNAL(connected()), this, SLOT(connectReady()));
  connect(this-&gt;tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnectedReady()));

}

TCPClient::~TCPClient()
{

}

bool TCPClient::initiateService()
{
  this-&gt;tcpSocket-&gt;connectToHost(this-&gt;hostName.c_str(), this-&gt;port);
  this-&gt;tcpSocket-&gt;waitForConnected(5000);
}

void TCPClient::connectReady()
{
  this-&gt;is_connected = true;
}

void TCPClient::disconnectedReady()
{

}


bool TCPClient::sendBabelPacket(Protocol::BabelPacket &amp;packet)
{
  if(this-&gt;tcpSocket-&gt;state() == QAbstractSocket::ConnectedState &amp;&amp; is_connected)
  {
    std::cout &lt;&lt; "writing ... size : " &lt;&lt; sizeof(Protocol::BabelPacket) + packet.dataLength&lt;&lt;std::endl;
    this-&gt;tcpSocket-&gt;write((const char *)&amp;packet, sizeof(Protocol::BabelPacket) + packet.dataLength);
    //this-&gt;tcpSocket-&gt;flush();
    return true;
  }
  else
  {
    std::cout &lt;&lt; "socket close" &lt;&lt; std::endl;
    return false;
  }
}


void TCPClient::shutDown()
{
  this-&gt;tcpSocket-&gt;abort();
}

void TCPClient::displayError(QAbstractSocket::SocketError socketError)
{

}

void TCPClient::readMessage()
{
  char buffer[sizeof(Protocol::BabelPacket)];
  this-&gt;tcpSocket-&gt;read(buffer, sizeof(Protocol::BabelPacket));
}
</code></pre>

<p>When I call <code>write</code>, it returns the right amount of bytes.</p>

<p>I use this class in a GUI context, in the same thread.</p>