QTextEdit not deleted when implemented as list
Dear All
I have list of QTextEdit, I am creating the edit box and then trying to delete but its not deleting. Can u anyone tell me what I am doing wrong.
Code:
QList<QTextEdit *> list;
int w = 100;
int h= 25;
int incre=0;
for(i=0; i<2; i++)
{
list.at(i)->setGeometry(0,0+incre,w,h);
list.at(i)->show();
incre = incre+h+10;
}
int cnt = list.count();
for(int i=0; i<cnt; i++)
delete list.at(i);
list.clear();
But even after deleting the edit boxes I can still see them, means they’re not being deleted. Whats wrong , any help would be appreciated.
Re: QTextEdit not deleted when implemented as list
Use takeAt() instead of at()
Code:
//int cnt = list.count();
//for(int i = 0; i < cnt; i++)
// delete list.takeAt(i);
//list.clear();
while(list.count())
delete list.takeAt(0);
Re: QTextEdit not deleted when implemented as list
at() should be ok too. The problem is elsewhere. What is the value of cnt in line #13?
Re: QTextEdit not deleted when implemented as list
Agree, it is valid and working code (or it would be if int would be added before"i" in the first loop).
Re: QTextEdit not deleted when implemented as list
using at() should also work
probably your delete is never being called, set a breakpoint and see it ever gets executed
Re: QTextEdit not deleted when implemented as list
From what I understand these are two separate pieces of code. It would be stupid to create something and delete it three lines later without using it. So there is a good chance the list goes out of scope (or is a member variable) and the OP creates a new one with the same name expecting it to have the same content. That's why I asked for the size of the list prior to deleting items from it.