It's 1000000 times better to just leave the data in the socket, and return. The next time this signal is fired, you'll probably have enough. So:

Qt Code:
  1. void MyClass::slotConnectedToReadyRead()
  2. {
  3. // Bad:
  4. static QByteArray data; // static data is bad
  5. data += readAll(); // unnecessary copy
  6. if (data.size() < 256)
  7. return;
  8.  
  9. // Good:
  10. if (bytesAvailable() < 256)
  11. return;
  12. QByteArray data = read(256); // local variable is good
  13. }
To copy to clipboard, switch view to plain text mode