Results 1 to 2 of 2

Thread: How to "CLEAR" data on QTcpSocket

  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Default How to "CLEAR" data on QTcpSocket

    Can I clear data on tcpSocket without read it ?

    I tried like this but still not working.
    Qt Code:
    1. qDebug() << myTcpSocket->size(); //result 3229696
    2. myTcpSocket->reset();
    3. qDebug() << myTcpSocket->size(); //result 3229696
    To copy to clipboard, switch view to plain text mode 

    If like this, is working. But, make a delay if data size is big.
    Qt Code:
    1. qDebug() << myTcpSocket->size(); //result 3229696
    2. myTcpSocket->readAll();
    3. qDebug() << myTcpSocket->size(); //result 0
    To copy to clipboard, switch view to plain text mode 

    Thank's before..

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to "CLEAR" data on QTcpSocket

    To clear the buffer of the TCP socket, you need to read it.
    But, if the socket can still receive data, it will fill the buffer again, and again, till everything is received. Thus, also close the connection before reading the buffer for the last time.

    If the data is received in large blocks, you can set the read buffer size to receive smaller data blocks. This will generate more overhead that gets more significant the smaller the blocks are.

Similar Threads

  1. QTcpSocket read duplicate data, but only on "bad channel"
    By creatron in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2010, 19:17
  2. Replies: 1
    Last Post: 7th April 2010, 21:46
  3. Replies: 3
    Last Post: 25th August 2009, 13:03
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.