Results 1 to 2 of 2

Thread: QTreeView PARENT & CHILD

  1. #1
    Join Date
    Feb 2009
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Unhappy QTreeView PARENT & CHILD

    hi i do this code:

    Qt Code:
    1. QItemSelectionModel *sel=dirv->treeView->selectionModel();
    2.  
    3. QModelIndexList modelindex;
    4.  
    5. QVariant data;
    6.  
    7. QAbstractItemModel *am=dirv->treeView->model();
    8.  
    9. modelindex=sel->selectedIndexes();
    10.  
    11. int i=0;
    12.  
    13. QList<QModelIndex> index(modelindex);
    14.  
    15. for(i=0; i<index.size();++i){
    16. QModelIndex mi=index.at(i);
    17. QVariant data=am->data(mi,0);
    18.  
    19. QString s = data.toString();
    20. QByteArray bytArr = s.toLatin1();
    21. char *pr = bytArr.data();
    22.  
    23. QModelIndex mi2= index.at(1).parent();
    24. QVariant data2=am->data(mi2,0);
    25. QString s2 = data2.toString();
    26. QByteArray bytArr2 = s2.toLatin1();
    27. char *pr2 = bytArr2.data();
    28.  
    29. cout << i << "child:::" << pr << "---parent:::" << pr2 << endl;
    30. }
    To copy to clipboard, switch view to plain text mode 

    why if i selected 5 different item in different folder
    the parent is the first selected item ????????

    exemple:
    i select
    x.jpg ---> image
    and
    y.jpg ---> img

    output:
    child:::x.jpg---parent:::image
    child:::y.jpg---parent:::image
    Last edited by jpn; 10th February 2009 at 14:51. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2009
    Posts
    32
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTreeView PARENT & CHILD

    sorry i'm very tired the error was

    QModelIndex mi2= index.at(1).parent();

    correct is
    QModelIndex mi2= index.at(i).parent();



    but after 8 hours on pc..

Similar Threads

  1. connecting child to parent window...
    By sumit in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2008, 21:28
  2. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40
  3. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00
  4. Infinite loop - resize parent from child
    By bitChanger in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2006, 13:21
  5. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 15:13

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.