[Qt-interest] delete item of QVector on a QLayout

Andre Somers andre at familiesomers.nl
Fri Feb 19 10:50:21 CET 2010


Frank Lutz wrote:
> Hi,
>
> i do have a problem to delete a part from a vector.
> If i use push_back it will delete the item from the vector, but not from 
> the QLayout.
> If i use delete the item will delete at the QLayout, but not at the vector.
> If i use both it will run fine under linux, but on windows i get 
> correctly a crash because on second it don't exists any more.
>
> So please, what can i do, to delete the vector item from the layout?
>
>
> thank many!
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>   
I don't get what you are doing. Perhaps a sample of code would clarify it.
QVector::push_back does not delete anything, it appends to the vector. 
Also, I am confused what it is that you put in your vector. Pointers to 
your widgets, I hope? Or better yet, QPointers?

In general, you can delete an object only once. Removing a (pointer to) 
an item from a container (like a QList or a QVector) is not the same as 
deleting that item. If you delete the object, it should automatically be 
removed from the QLayout, but the pointer to it will not automatically 
be removed from the container.

André




More information about the Qt-interest-old mailing list