PDA

View Full Version : [Fixed] QTcpSocket reads 99%



scarecr0w132
22nd October 2013, 06:46
Fixed, it was because I was using tcpSocket->waitForReadyRead() inside readyread signal, in docs it says not to do that, and read inside if (tcpSocket->bytesAvailable() > 0)

Hi,

I am getting strange behavior from QTcpSocket.
I am using a threaded server. Occasionally when the client requests data (15mb) it transfers fine, but this only works VERY occasionally and it is completely random if it transfers it all or not. 99% of the time it reads 99% of the data (reads 14795240 bytes out of 14836010 bytes).

Client:



...
QByteArray byteArray;
void Client::readyReadSignal() {
if (tcpSocket->waitForReadyRead()) {
byteArray.append(tcpSocket->readAll());
}
qDebug() << "Read: " + QString::number(byteArray.size()) + " should read: " + QString::number(fileSize);
if (byteArray.size() == fileSize) {
updateFile = new QFile("hello.exe");
if(updateFile->open(QIODevice::WriteOnly)) {
updateFile->write(byteArray);
}
tcpSocket->close();
}
...


Output at end:
"Read: 14802704 should read: 14836010

Has anyone else had this behaviour?
Thankyou