PDA

View Full Version : General destroy question



qlands
16th September 2011, 08:45
Hi,

I have a class that looks like this:



struct moduleFieldDef
{
QString code;
QString description;
QVariant value;
QVariant previousValue;
QAbstractItemDelegate* delegate;
};

typedef moduleFieldDef TmoduleFieldDef;

class fieldInColModel : public QAbstractTableModel
{
Q_OBJECT
public:
fieldInColModel(QObject *parent=0);
~fieldInColModel();

private:
QList<TmoduleFieldDef> m_fields;
};


In the implementation m_fields gets filled with a series of fields some of them with a valid * to a delegate. Both the class and the * to delegates share the same parent (a QDialog).

Now, when the class gets destroyed what happens to the list m_fields, the fields it contains and the valid * to a delegates? Do the valid * to a delegates gets destroyed too? or they will get destroy after (when its parent gets destroyed)?

Thanks,
Carlos.

Rachol
16th September 2011, 08:54
If you ask if the delegates get destroyed,when m_fields is destroyed, the answer is "no".

stampede
16th September 2011, 09:10
As I've posted in your other thread, someday you will regret such thing:


struct moduleFieldDef
{
...
QAbstractItemDelegate* delegate;
};

What if you pass this pointer to a view and it gets deleted ? You are left with dangling pointer. I think its better safe than sorry :


struct moduleFieldDef
{
...
QPointer<QAbstractItemDelegate> delegate;
};

QPointer (http://doc.qt.nokia.com/latest/qpointer.html)