void QObjectPrivate::deleteChildren(){ ...... for (int i = 0; i < children.count(); ++i) { currentChildBeingDeleted = children.at(i); children[i] = 0; delete currentChildBeingDeleted;//вот здесь } ......}
C++ (Qt)QWidget::~QWidget(){ ... if (!d->children.isEmpty()) d->deleteChildren(); ...}
if (!d->children.isEmpty()) d->deleteChildren();
class MyLabel : public QLabel { public: MyLabel( const QString & txt, QWidget * parent = 0 ) : QLabel(txt, parent) {} ~MyLabel( void ) { qDebug() << "MyLabel destroyed"; }};
C++ (Qt)typedef int A; class B{public: A * create( int index ) { return values_[ index ] = new A; } void destroy( int index ) { delete values_.take( index ); } void clear() { foreach ( A * value, values_ ) delete value; values_.clear(); } private: QHash<int,A*> values_;};