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:
void MyClass::slotConnectedToReadyRead()
{
// Bad:
data += readAll(); // unnecessary copy
if (data.size() < 256)
return;
// Good:
if (bytesAvailable() < 256)
return;
QByteArray data
= read
(256);
// local variable is good }
void MyClass::slotConnectedToReadyRead()
{
// Bad:
static QByteArray data; // static data is bad
data += readAll(); // unnecessary copy
if (data.size() < 256)
return;
// Good:
if (bytesAvailable() < 256)
return;
QByteArray data = read(256); // local variable is good
}
To copy to clipboard, switch view to plain text mode
Bookmarks