Qt-interest Archive, September 2007
"delete"ing a QTcpSocket
Message 1 in thread
Hi. I use to do network programming the non-event way, namely:
QTcpSocket *s = new QTcpSocket;
s->connectToHost(someHost, somePort);
s->waitForConnected();
s->write("Hello, World!");
s->waitForBytesWritten();
s->disconnectFromHost();
s->waitForDisconnect();
delete s;
However, it uses to assert upon deletion. When I don't delete, the
memory is of course not freed and creates a leak.
I tried to use a local variable instead of a pointer, but the memory
is just not freed, it's growing without an end.
To be more particular; I use this code (with all the
return-on-error-stuff) in a thread.
Is there a way to somehow free this memory? I tried to use abort() and
close() instead of disconnectFromHost(), without any difference in
behaviour.
I'm with Qt Commercial 4.2.2 on Windows XP Professional SP2 with
Visual C++ 6.0, but I have the same behaviour with MinGW and VS2005
Professional.
--
[ signature omitted ]
Message 2 in thread
On Wednesday 26 September 2007 09:59, fhd@xxxxxxxxxxx wrote:
> Hi. I use to do network programming the non-event way, namely:
>
> QTcpSocket *s = new QTcpSocket;
> s->connectToHost(someHost, somePort);
> s->waitForConnected();
> s->write("Hello, World!");
> s->waitForBytesWritten();
> s->disconnectFromHost();
> s->waitForDisconnect();
> delete s;
>
> However, it uses to assert upon deletion. When I don't delete, the
> memory is of course not freed and creates a leak.
> I tried to use a local variable instead of a pointer, but the memory
> is just not freed, it's growing without an end.
This shouldn't be happen, there must be something else wrong with your code.
> To be more particular; I use this code (with all the
> return-on-error-stuff) in a thread.
>
> Is there a way to somehow free this memory? I tried to use abort() and
> close() instead of disconnectFromHost(), without any difference in
> behaviour.
does
s->deleteLater()
works for you?
Mathias
--
[ signature omitted ]
Message 3 in thread
On Wed, Sep 26, 2007 at 09:59:48AM +0200, fhd@xxxxxxxxxxx wrote:
> Hi. I use to do network programming the non-event way, namely:
>
> QTcpSocket *s = new QTcpSocket;
> s->connectToHost(someHost, somePort);
> s->waitForConnected();
> s->write("Hello, World!");
> s->waitForBytesWritten();
> s->disconnectFromHost();
> s->waitForDisconnect();
> delete s;
>
> However, it uses to assert upon deletion. When I don't delete, the
> memory is of course not freed and creates a leak.
> I tried to use a local variable instead of a pointer, but the memory
> is just not freed, it's growing without an end.
> To be more particular; I use this code (with all the
> return-on-error-stuff) in a thread.
What assertion? Does s->deleteLater() help?
regards,
Andre
--
[ signature omitted ]