[Qt-interest] can't delete QStandardItem buffer after insert in QStandardItemModel
wya
htyoung.cn at gmail.com
Fri Nov 19 18:16:16 CET 2010
Hi,
progrI use QTreeView and QStandardItemModel to display dynamic row items,
if the rows more than 100,function will delete first row and add one row at
last postion.
Let QTreeView always display 100 rows.
I found the memory size raise even if I deleted the list QStandardItem* in
the rows.
It seems function "removeFirstRow()" not remove the QStandardItem's buffer
which allocated in the function "addItem()".
I want understand why I can't free QStandardItem buffer in the
removeFirstRow.
Any comment.welcome.
The simple code is follwoing:
/////////////////////////////////////////////////////////////////////
// init the tree and QStandardItemModel
void YTraceList::init()
{
QTreeView *m_treeView= new QTreeView(this);
m_treeView->setModel(m_proxyModel);
// add column
m_itemModel=new QStandardItemModel(0, 7, this);
m_itemModel->setHeaderData(i++, Qt::Horizontal, QObject::tr("Time"));
m_itemModel->setHeaderData(i++, Qt::Horizontal, QObject::tr("Chn"));
m_itemModel->setHeaderData(i++, Qt::Horizontal, QObject::tr("ID"));
m_itemModel->setHeaderData(i++, Qt::Horizontal, QObject::tr("Name"));
m_itemModel->setHeaderData(i++, Qt::Horizontal, QObject::tr("Dir"));
m_itemModel->setHeaderData(i++, Qt::Horizontal, QObject::tr("DLC"));
m_itemModel->setHeaderData(i++, Qt::Horizontal, QObject::tr("Data"));
m_treeView->setModel(m_itemModel);
}
....
.......
///////////////////////////////////////////////////////////////////////////////
// here I append the rows
void YTraceList::addItem( QStringList & lists)
{
//model->insertRow(0);
QList<QStandardItem*> itemLits;
QStandardItem *tmp;
for (int i=0;i< 7; i++)
{
tmp=new QStandardItem( lists.at(i) );
itemLits.append( tmp);
}
m_itemModel->appendRow(itemLits);
}
///////////////////////////////////////////////////////////////////////////////////
// here I remove one row.but memery continue raise
void YTraceList::removeFirstRow()
{
int i=0;
int rows= m_itemModel->rowCount();
QList<QStandardItem*> itemList;
QStandardItem *tmp;
for(int j=0;j<rows;j++)
{
itemList=m_itemModel->takeRow(0);
for(i=0; i<itemList.size();i++)
{
tmp= itemList.at(i);
if( tmp !=NULL)
{
delete tmp;
tmp =NULL;
}
}
}
}
wya
20. Nov. 2010
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101120/822b40b4/attachment.html
More information about the Qt-interest-old
mailing list