PDA

View Full Version : QTextEdit not deleted when implemented as list



sujan.dasmahapatra
23rd June 2011, 16:18
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.


QList<QTextEdit *> list;
int w = 100;
int h= 25;
int incre=0;
for(i=0; i<2; i++)
{
list.append(new QTextEdit(this));
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.

Santosh Reddy
23rd June 2011, 17:57
Use takeAt() instead of at()

//int cnt = list.count();
//for(int i = 0; i < cnt; i++)
// delete list.takeAt(i);
//list.clear();

while(list.count())
delete list.takeAt(0);

wysota
23rd June 2011, 18:15
at() should be ok too. The problem is elsewhere. What is the value of cnt in line #13?

Rachol
23rd June 2011, 18:36
Agree, it is valid and working code (or it would be if int would be added before"i" in the first loop).

Santosh Reddy
24th June 2011, 00:56
using at() should also work

probably your delete is never being called, set a breakpoint and see it ever gets executed

wysota
24th June 2011, 08:46
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.