Unsolved Help with QTreeWidget simple example
-
Hi i am trying to add different child to my qtreewidget but i couldn't. The code:
void MainWindow::AddRoot() { logado = true; //part of my program ui->frameLogin->show(); ui->frameConexion->show(); int i,j; QTreeWidgetItem *item = new QTreeWidgetItem(ui->arbolConectados); QStringList contactos = cliente.rosterManager().getRosterBareJids(); for(i=0;i<contactos.length();i++) { item->setText(0,contactos[i]); QStringList recursos = cliente.rosterManager().getResources(contactos[i]); for(j=0;j<recursos.length();j++) { AddChild(item); } } } void MainWindow::AddChild(QTreeWidgetItem *parent){ QTreeWidgetItem *item = new QTreeWidgetItem(); parent->addChild(item); }
But when i add the child only add me one the old is deleted.
the headers:
void AddChild(QTreeWidgetItem *parent); -
Hi,
Because you are using the same item in your loop. You create the item once, overwrite it's content and the keep adding it.