Results 1 to 3 of 3

Thread: Adding a child of model

  1. #1
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Adding a child of model

    When i add a child to model the subsequent offspring overwrites the previous , why??
    Qt Code:
    1. void MainWindow::addChild()
    2. {
    3. qDebug()<<"Slot activ";
    4. QModelIndex index = ui->treeView->selectionModel()->currentIndex();
    5. QAbstractItemModel *model = ui->treeView->model();
    6.  
    7. if (model->columnCount(index) == 0) {
    8. if (!model->insertColumn(0, index))
    9. {
    10. return;
    11. }
    12. }
    13.  
    14. if (!model->insertRow(0, index))
    15. {
    16. return;
    17. }
    18.  
    19. int column = ui->treeView->selectionModel()->currentIndex().column();
    20. int row=ui->treeView->selectionModel()->currentIndex().row();
    21.  
    22.  
    23. model->insertColumn(column , index);
    24. model->setData(model->index(row, column, index), QVariant(linkWWW->text()), Qt::EditRole);
    25. qDebug()<<column;
    26.  
    27. model->insertColumn(column +1, index);
    28. model->setData(model->index(row, column + 1 , index), QVariant(nameWWW->text()), Qt::EditRole);
    29. qDebug()<<column;
    30.  
    31. model->insertColumn(column +2, index);
    32. model->setData(model->index(row, column + 2 , index), QVariant(tegWWW->text()), Qt::EditRole);
    33. qDebug()<<column;
    34.  
    35. model->insertColumn(column +3, index);
    36. model->setData(model->index(row, column + 3 , index), QVariant(tegWWW->text()), Qt::EditRole);
    37. qDebug()<<column;
    38.  
    39. }
    To copy to clipboard, switch view to plain text mode 


    the first child added to child_1 child_3
    second child added to child_4 child_6
    as a result of the second child of the first erased

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Adding a child of model

    Hi, probably the row that you use in the setData calls does not change.

    Ginsengelf

  3. #3
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding a child of model

    tried to change the way
    but it did not work
    Qt Code:
    1. int row = rowCount(); // number of folders already in the model
    2. insertRow(row); // add a new row
    3. QModelIndex ind = index(row, 0); // index of the newly created item
    4. insertColumn(0, ind); // add a column for future children of the item
    To copy to clipboard, switch view to plain text mode 
    by some algorithm to change ???
    Last edited by _exp_; 6th August 2010 at 14:32.

Similar Threads

  1. Adding a child of treeView
    By _exp_ in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2010, 11:11
  2. Adding signal to own model class
    By michciu in forum Qt Programming
    Replies: 2
    Last Post: 24th April 2010, 04:00
  3. Replies: 5
    Last Post: 18th April 2010, 23:31
  4. Replies: 5
    Last Post: 17th February 2009, 04:35
  5. Limitation when adding more than 256 items to a model
    By darkadept in forum Qt Programming
    Replies: 5
    Last Post: 25th May 2006, 15:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.