PDA

View Full Version : Qtreewidget not updating data



phillip_Qt
11th November 2009, 12:35
Hi All
I'm writing an application where i'm using tree widget. if i click on the treewidget an input dialog is poping up and asking to enter a string. i need to update that string in treewidget. Below is my code. But its not updating in tree widget. Can ny body help me.



bool b;
QString name = QInputDialog::getText( this,
tr( "New name" ),
tr( "Please enter the name " ),
QLineEdit::Normal, tr( "New classroom" ), &b);

if(b && !name.isEmpty())
{
QStringList strlist;
strlist.push_back(classroom_name);
QTreeWidgetItem temptreelst(strlist);
m_name.append(&temptreelst); //QList<QTreeWidgetItem *> m_name is to colect the list of names and amember variable
ui->treeWidget->addTopLevelItem(&temptreelst);
ui->treeWidget->expandAll();

}

Thank u all.

Lykurg
11th November 2009, 13:46
First, in your code you don't use the asked string name. Second, create your QTreeWidgetItem on the heap, because else it gets deleted after the scope.

phillip_Qt
12th November 2009, 04:10
First, in your code you don't use the asked string name. Second, create your QTreeWidgetItem on the heap, because else it gets deleted after the scope.

thank u for quick response. there was ll mistake in the code. Below i've posted the code.


bool b;
QString name = QInputDialog::getText( this,
tr( "New name" ),
tr( "Please enter the name " ),
QLineEdit::Normal, tr( "New classroom" ), &b);

if(b && !name.isEmpty())
{
QStringList strlist;
strlist.push_back(name );
QTreeWidgetItem temptreelst(strlist);
m_name.append(&temptreelst); //QList<QTreeWidgetItem *> m_name is to colect the list of names and amember variable
ui->treeWidget->addTopLevelItem(&temptreelst);
ui->treeWidget->expandAll();

}

temptreelst is QTreeWidgetItem object. But still its nt updating.:(