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

Denis Shienkov denis.shienkov at gmail.com
Sun Jan 10 09:03:59 CET 2016


Ok, this is enough :)

09.01.2016 18:49, Thiago Macieira пишет:
> 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
>




More information about the Development mailing list