Results 1 to 1 of 1

Thread: [Fixed] QTcpSocket reads 99%

  1. #1
    Join Date
    May 2013
    Posts
    45
    Thanks
    6
    Thanked 6 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Exclamation [Fixed] QTcpSocket reads 99%

    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:

    Qt Code:
    1. ...
    2. QByteArray byteArray;
    3. void Client::readyReadSignal() {
    4. if (tcpSocket->waitForReadyRead()) {
    5. byteArray.append(tcpSocket->readAll());
    6. }
    7. qDebug() << "Read: " + QString::number(byteArray.size()) + " should read: " + QString::number(fileSize);
    8. if (byteArray.size() == fileSize) {
    9. updateFile = new QFile("hello.exe");
    10. if(updateFile->open(QIODevice::WriteOnly)) {
    11. updateFile->write(byteArray);
    12. }
    13. tcpSocket->close();
    14. }
    15. ...
    To copy to clipboard, switch view to plain text mode 

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

    Has anyone else had this behaviour?
    Thankyou
    Last edited by scarecr0w132; 22nd October 2013 at 06:12.

Similar Threads

  1. Replies: 7
    Last Post: 11th November 2014, 08:40
  2. QTcpSocket reads partially string
    By Edder in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2012, 20:29
  3. Replies: 1
    Last Post: 15th September 2011, 21:25
  4. Replies: 1
    Last Post: 13th April 2011, 23:08
  5. QIODevice read() problem (reads more than maxSize)
    By m15ch4 in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2011, 11:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.