What happens when i call clear() of QList<QObject *> variable?
I have the following code:
Code:
QList<QObject *> m_devices;
m_devices.append(new Data::Device(info));
When do I call the method m_devices.clear() from QList, the allocated memory (new Data::Device(info)) will be free correctly or I need do delete one by one before?
Re: What happens when i call clear() of QList<QObject *> variable?
If "info" is a QObject and is assigned as parent to Data::Device objects, then memory will be freed after "info" object is deleted.
Otherwise you have to delete items manually, for example:
Code:
qDeleteAll(m_devices);
clear() will only remove the pointers from memory, but will not call "delete" on them.