I think I found the reason. 58th line of Connection code in the first post is:
Qt Code:
  1. lBufLength += mSocket->bytesAvailable();
To copy to clipboard, switch view to plain text mode 
I guess it should be:
Qt Code:
  1. lBufLength = mSocket->bytesAvailable();
To copy to clipboard, switch view to plain text mode