Just for the record :
Finally, I managed my QAbstractSocket::waitForBytesWritten() with the following code from the QT documentation and I don't get the error message
client.disconnectFromHost();
client.waitForDisconnected(1000))
qDebug("Disconnected!");
else
qDebug() << "Error when DisconnectFromHost :" << client.error();
client.disconnectFromHost();
if(client.state() == QAbstractSocket::UnconnectedState ||
client.waitForDisconnected(1000))
qDebug("Disconnected!");
else
qDebug() << "Error when DisconnectFromHost :" << client.error();
To copy to clipboard, switch view to plain text mode
The was no "read" error at all. In fact, the problem was in the client side.
I just forget to read in the QTcpSocket until there was not data. In the exemple in the link that I posted, the client read just one time.
This way, the server read and write data and the client read it.
The second time the server read data and write it in the TCPSocket, but it is not read or flushed because the client doesn't read it.
And the third time, the server read data and it is not able to write it in the socket.
This is the new client code. The previous code didn't have the while(client->waitForReadyRead()) but just a one time waitForReadyRead. That was my problem from the beginning.
{
qDebug("File connot be opened.");
exit(0);
}
else
{
while(client->waitForReadyRead())
{
QByteArray read
= client
->read
(client
->bytesAvailable
());
qDebug() << "Read : " << read.size();
qDebug() << "Written : " << file.write(read);
}
}
file.close();
QFile file(filename);
if(!(file.open(QIODevice::Append)))
{
qDebug("File connot be opened.");
exit(0);
}
else
{
while(client->waitForReadyRead())
{
QByteArray read = client->read(client->bytesAvailable());
qDebug() << "Read : " << read.size();
qDebug() << "Written : " << file.write(read);
}
}
file.close();
To copy to clipboard, switch view to plain text mode
Thanks for all.
Bookmarks