c++ - Qt, Dynamic allocation of memory -


i have little question: made little program every time user click on qpushbuton new object created pointer, here code:

ajoute *az = new ajoute; qvboxlayout *layoutprincipal = new qvboxlayout; 

the problem every object have been created have same name if want delete object there have error ?

p.s : sorry bad english, i'm french

the problem every object have been created have same name if want delete object there have error?

it seems creating group of dynamically allocated objects , don't know how store pointers. simplest way use qvector<ajoute*> , store dynamically allocated objects:

qvector<ajoute*> v; 

now whenever create ajoute do:

v.push_back( new ajoute ); 

that add pointer @ end of vector (container). can access them in order doing:

v[0]; // first v[1]; // second v[2]; // third 

and can delete them as:

delete v[0]; // example 

just remember delete pointer inside vector well:

v.remove(0); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -