No, it's still wrong, you are discarding previous content of the buffer.
This is correct (by the way, there are numerous threads in this forum where I explain this particular situation, how come you didn't encounter any of the threads while using our search?):
Qt Code:
  1. QByteArray buffer; // global or member variable
  2. void Cls::onSocketReadyRead() {
  3. buffer.append(socket->readAll());
  4. tryProcessData();
  5. }
  6.  
  7. void Cls::tryProcessData() {
  8. forever {
  9. // for the sake of the example I'm assuming my record is always 24 bytes long
  10. if(buffer.size()<24) return;
  11. QByteArray record = buffer.left(24);
  12. processRecord(record);
  13. }
  14. }
To copy to clipboard, switch view to plain text mode 

The above code has one small flaw introduced for purpose so that you need to understand completely what the code does before actually using it.