I want to know if QHash, QList makes a copy of the items inserted into them or what ??
Suppose I have a function CreateList()
class MyNode
{
int id;
QScene *scene; // pointer to a scene or any other class based on id.
public :
MyNode(QScene *s)
{ scene = s;
id = 0; // or some unique value
}
};
QList<MyNode> list;
void CreateList()
{
MyNode node(this->pScene);
list.append(node);
}
class MyNode
{
int id;
QScene *scene; // pointer to a scene or any other class based on id.
public :
MyNode(QScene *s)
{ scene = s;
id = 0; // or some unique value
}
};
QList<MyNode> list;
void CreateList()
{
MyNode node(this->pScene);
list.append(node);
}
To copy to clipboard, switch view to plain text mode
Here I have added just one item, though multiple items may be insterted in the list. I want to know when CreateList function is exited, wll list still have valid copy of node ??
also what if i have pointers instead of objects..
like
QList<MyNode*> list;
void CreateList()
{
MyNode *node = new MyNode(this->pScene); // node contains some
list.append(node);
}
QList<MyNode*> list;
void CreateList()
{
MyNode *node = new MyNode(this->pScene); // node contains some
list.append(node);
}
To copy to clipboard, switch view to plain text mode
in this case how do i delete the actual nodes created. Does list.clear() call the destructor too ?? if not what is the safe way of freeing the memory when a list of pointers is cleared ?
I think I know the answers, but still a little confused,so asking in the forum, (i know i sound a little stupid here )
Thx in advance
Bookmarks