PDA

View Full Version : Hidden problem with dynamic created pointer?



jboban
30th June 2012, 13:13
Is there any hidden problem with this code, please? I'w worried about living time of dynamic created "*connection" pointer.

void TMyTCPSrv::incomingConnection(int sockDesc)
{
TConnection *connection = new TConnection(this);
connection->setSocketDescriptor(sockDesc);

// Send read message to this
connect(connection, SIGNAL(toLocalServer(const QString&)),
this, SLOT(onReadFromClient(const QString&)), Qt::QueuedConnection);
}

class TConnection: public QTcpSocket
{
...
};

amleto
30th June 2012, 14:29
TConnection will live for as long as TMyTCPSrv lives (no shorter, no longer), presuming that you passing 'this' to the ctor is a parent argument.

jboban
30th June 2012, 18:37
Ok. Thank you ;)