Tree widget not updating the data
Hi All
I need u ppls help. in my treewidget I've added some items. Now i need some child item to a perticular treewidget item. In my code i'm getting the index of item, where i need to insert the child item. but treewidgetitem->addchild(index,treewidgetitem) not updating the child item. Below i've pasted my code. Add addComputers() is the methode where i'm updating child. Can any body tell me what is the wrong in this code. :confused:
Code:
Header file
------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
{
Q_OBJECT
public:
~MainWindow();
private:
Ui::MainWindow *ui;
private:
//! To collect the list of classrooms and computers added to the coressponding classroom
QList<QTreeWidgetItem *> *m_ClassRoom;
QList<QTreeWidgetItem *> m_computersAddedToCalssroom;
QList<QTreeWidgetItem *> temp;
private slots:
//! To add Computers
void addComputers();
//! To add classroom
void addClassRoom();
private slots:
//! To handle the right click event in The right side bar
void ContextMenuDisplayMethod
(const QPoint &);
private:
private:
//! treewidget context menu
QList<QAction *> actionsList;
private:
//SingleClass SingleClassobj;
//! To add sub Items in tree widget
//! To add sub Items in tree widget
int * index;
};
#endif // MAINWINDOW_H
.cpp File
----
void addComputersToClassroom()
{
m_clientSettingsDlgobj.exec();
m_strIpEntered = m_clientSettingsDlgobj.getIP();;
m_strClassRoomSel = m_clientSettingsDlgobj.getSelClassRoom();
qDebug()<< "MainWindow::addComputers IP Entered : "<<m_strIpEntered;
qDebug()<< "MainWindow::addComputers Cls Room entered : "<<m_strClassRoomSel;
temp = ui->treeWidget->findItems(m_strClassRoomSel , Qt::MatchExactly);
qDebug()<< "MainWindow::addComputers top level size: "<<ui->treeWidget->topLevelItemCount();
for(int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
{
if(ui->treeWidget->topLevelItem(i)->text(0) == m_strClassRoomSel)
{
qDebug()<< "MainWindow::addComputers : Inside the iterator: ";
m_Childlist->setText(0, m_strIpEntered);
m_Childlist->setText(1, m_strIpEntered);
index = new int;
ui->treeWidget->setCurrentItem(temp.at(0));
*m_modelIndex = (ui->treeWidget->currentIndex());
*index = (m_modelIndex->data().toInt());
qDebug()<<"index : "<<*index;// I'm getting the index
m_treelist->insertChild(*index,m_Childlist);// This is not adding the child to classroom
return;
}
}
}
void addClassRoom()
{
bool bOk = false;
tr( "New classroom" ),
tr( "Please enter the name of the classroom you "
"want to create." ),
QLineEdit::Normal, tr
( "New classroom" ),
&bOk
);
if(!classroom_name.isEmpty())
{
bool bTemp = false;
for(int i = 0; i < m_strlistComputer.size(); i++)
{
if(m_strlistComputer.at(i) == classroom_name)
bTemp = true;
}
if(bTemp == false)
{
m_strlistComputer.append(classroom_name);
m_treelist->setText(0,classroom_name);
m_ClassRoom->append(m_treelist);
ui->treeWidget->addTopLevelItem(m_treelist);
}
}
}
Thank u all.
Re: Tree widget not updating the data
why you can't do like this?
Code:
for(int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
{
if(parent->text(0) == m_strClassRoomSel)
{
qDebug()<< "MainWindow::addComputers : Inside the iterator: ";
m_Childlist->setText(0, m_strIpEntered);
m_Childlist->setText(1, m_strIpEntered);
return;
}
}
and remove this strange code snippet
Code:
...
index = new int;
ui->treeWidget->setCurrentItem(temp.at(0));
*m_modelIndex = (ui->treeWidget->currentIndex());
*index = (m_modelIndex->data().toInt());
qDebug()<<"index : "<<*index;// I'm getting the index
m_treelist->insertChild(*index,m_Childlist);// This is not adding the child to classroom
...
Re: Tree widget not updating the data
Quote:
Originally Posted by
spirit
why you can't do like this?
Code:
for(int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
{
if(parent->text(0) == m_strClassRoomSel)
{
qDebug()<< "MainWindow::addComputers : Inside the iterator: ";
m_Childlist->setText(0, m_strIpEntered);
m_Childlist->setText(1, m_strIpEntered);
return;
}
}
and remove this strange code snippet
Code:
...
index = new int;
ui->treeWidget->setCurrentItem(temp.at(0));
*m_modelIndex = (ui->treeWidget->currentIndex());
*index = (m_modelIndex->data().toInt());
qDebug()<<"index : "<<*index;// I'm getting the index
m_treelist->insertChild(*index,m_Childlist);// This is not adding the child to classroom
...
Thank u. Its working. :)