But what if the DataSet* in the Map Gets Deleted Externally ?
will the qDeleteAll cause seg faults ??
But what if the DataSet* in the Map Gets Deleted Externally ?
will the qDeleteAll cause seg faults ??
We can't solve problems by using the same kind of thinking we used when we created them
Yes, of course. But it's the programmers responsibility not to delete objects he/she doesn't own. If you want a QMap with pointers to objects you don't own and those objects inherit QObject, you can use:
Qt Code:
QMap<Model *, QPointer<DataSet> > map;To copy to clipboard, switch view to plain text mode
In Qt3 you can use QGuardedPtr instead of QPointer. With such a mechanism qDeleteAll() should not make any harm as QPointer sets its internal pointer to 0 when the object it references gets deleted. And deleting null pointers is safe. On the other hand deleting pointers which you don't own doesn't make much sense, so the situation is purely academic.
Bookmarks