[Development] [autotests] Why the objects are used in 'heap' instead of 'stack'

Thiago Macieira thiago.macieira at intel.com
Sat Jan 9 16:49:33 CET 2016


On Saturday 09 January 2016 17:30:37 Denis Shienkov wrote:
> E.g. we can look on
> \qtbase\tests\auto\network\socket\qtcpsocket\tst_qtcpsocket.cpp as example,
> where in each test are used the new/delete:
> 
> void tst_QTcpSocket::foo()
> {
>      QTcpSocket *socket = new QTcpSocket;
>      // make tests
>      delete socket;
> }

Because they are not like that.

Here's an actual copy/paste from the test:

void tst_QTcpSocket::waitForReadyReadInASlot()
{
    QTcpSocket *socket = newSocket();
    [... other code ...]
    delete socket;
}

What's the difference?

QTcpSocket *tst_QTcpSocket::newSocket() const
{
    QTcpSocket *socket;
#ifndef QT_NO_SSL
    QFETCH_GLOBAL(bool, ssl);
    socket = ssl ? new QSslSocket : new QTcpSocket;
#else
    socket = new QTcpSocket;
#endif

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list