Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help with QTreeWidget simple example
Qt 6.11 is out! See what's new in the release blog

Help with QTreeWidget simple example

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 835 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jeronimo
    wrote on last edited by
    #1

    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);

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved