PDA

View Full Version : About QLocalSocket problem



wojiaoguowei
6th August 2015, 09:42
Below is my test code.I found clent applition memory leak.If I use QTcpSocket,the memory is normal.Is the problem the QT bug?

QLocalSocket ls;
ls.connectToServer("test");

int i = 0;

while (ls.waitForConnected())
{
QString message = QString::number(i) + "TTTTTTTTTT";

ls.write( message.toStdString().c_str(), message.length());

ls.flush();

ls.waitForBytesWritten();

Sleep(20);

i++;
}

anda_skoa
6th August 2015, 12:33
Are you sure you are leaking memory?
I.e. make sure you are not just seeing an increase use in memory because the data is still buffered and not read by the other side.

Also you should already think about encoding when converting the QString into an 8-Bit representation.
When the string contains any non-ASCII character, the 8-Bit representation could be longer than the QString representation, so data and length should be derived from the same input.

Cheers,
_

wojiaoguowei
7th August 2015, 03:26
Thanks for advance.But if I change to use QTcpServer and QTcpSocket,the memory leak is gone.Now I have used QTcpSocket.Everything is ok.;)