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.

Qt Code:
  1. Header file
  2. ------
  3. #ifndef MAINWINDOW_H
  4. #define MAINWINDOW_H
  5.  
  6.  
  7.  
  8. class MainWindow : public QMainWindow
  9. {
  10. Q_OBJECT
  11.  
  12. public:
  13. MainWindow(QWidget *parent = 0);
  14. ~MainWindow();
  15.  
  16. private:
  17. Ui::MainWindow *ui;
  18.  
  19.  
  20. private:
  21. //! To collect the list of classrooms and computers added to the coressponding classroom
  22. QList<QTreeWidgetItem *> *m_ClassRoom;
  23. QList<QTreeWidgetItem *> m_computersAddedToCalssroom;
  24. QStringList m_strlistComputer;
  25. QTreeWidgetItem *m_treelist;//(m_strlistComputer);
  26. QList<QTreeWidgetItem *> temp;
  27.  
  28.  
  29. private slots:
  30. //! To add Computers
  31. void addComputers();
  32. //! To add classroom
  33. void addClassRoom();
  34.  
  35. private slots:
  36. //! To handle the right click event in The right side bar
  37. void ContextMenuDisplayMethod(const QPoint &);
  38.  
  39. private:
  40. QMenu contextMenu;
  41.  
  42. private:
  43. //! treewidget context menu
  44. QAction * actionClassroom;
  45. QAction * actionComputer;
  46. QList<QAction *> actionsList;
  47.  
  48. private:
  49. //SingleClass SingleClassobj;
  50. QString m_strIpEntered;
  51. QString m_strClassRoomSel;
  52.  
  53.  
  54. //! To add sub Items in tree widget
  55. QModelIndex *m_modelIndex;
  56.  
  57.  
  58. //! To add sub Items in tree widget
  59. QTreeWidgetItem *m_Childlist ;
  60. int * index;
  61.  
  62. };
  63.  
  64. #endif // MAINWINDOW_H
  65.  
  66.  
  67.  
  68. .cpp File
  69. ----
  70. void addComputersToClassroom()
  71. {
  72.  
  73.  
  74. m_clientSettingsDlgobj.exec();
  75.  
  76. m_strIpEntered = m_clientSettingsDlgobj.getIP();;
  77. m_strClassRoomSel = m_clientSettingsDlgobj.getSelClassRoom();
  78.  
  79. qDebug()<< "MainWindow::addComputers IP Entered : "<<m_strIpEntered;
  80. qDebug()<< "MainWindow::addComputers Cls Room entered : "<<m_strClassRoomSel;
  81.  
  82. temp = ui->treeWidget->findItems(m_strClassRoomSel , Qt::MatchExactly);
  83.  
  84. qDebug()<< "MainWindow::addComputers top level size: "<<ui->treeWidget->topLevelItemCount();
  85.  
  86. QTreeWidgetItemIterator it(ui->treeWidget);
  87. for(int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
  88. {
  89.  
  90. if(ui->treeWidget->topLevelItem(i)->text(0) == m_strClassRoomSel)
  91. {
  92.  
  93. qDebug()<< "MainWindow::addComputers : Inside the iterator: ";
  94.  
  95. m_Childlist = new QTreeWidgetItem;
  96. m_Childlist->setText(0, m_strIpEntered);
  97. m_Childlist->setText(1, m_strIpEntered);
  98.  
  99. index = new int;
  100. m_modelIndex = new QModelIndex;
  101. ui->treeWidget->setCurrentItem(temp.at(0));
  102. *m_modelIndex = (ui->treeWidget->currentIndex());
  103. *index = (m_modelIndex->data().toInt());
  104. qDebug()<<"index : "<<*index;// I'm getting the index
  105.  
  106. m_treelist->insertChild(*index,m_Childlist);// This is not adding the child to classroom
  107.  
  108. return;
  109. }
  110. }
  111.  
  112. }
  113.  
  114. void addClassRoom()
  115. {
  116.  
  117. bool bOk = false;
  118. QString classroom_name = QInputDialog::getText( this,
  119. tr( "New classroom" ),
  120. tr( "Please enter the name of the classroom you "
  121. "want to create." ),
  122. QLineEdit::Normal, tr( "New classroom" ), &bOk );
  123.  
  124. if(!classroom_name.isEmpty())
  125. {
  126. bool bTemp = false;
  127. for(int i = 0; i < m_strlistComputer.size(); i++)
  128. {
  129. if(m_strlistComputer.at(i) == classroom_name)
  130. bTemp = true;
  131. }
  132. if(bTemp == false)
  133. {
  134. m_strlistComputer.append(classroom_name);
  135. m_treelist = new QTreeWidgetItem;
  136. m_treelist->setText(0,classroom_name);
  137. m_ClassRoom->append(m_treelist);
  138.  
  139. ui->treeWidget->addTopLevelItem(m_treelist);
  140. }
  141. }
  142. }
To copy to clipboard, switch view to plain text mode 

Thank u all.