Results 1 to 3 of 3

Thread: QTreeView is empty

  1. #1
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTreeView is empty

    hi,

    i implemented this treeview in my form among other items:

    Qt Code:
    1. Tree = new QTreeView(MainContainer);
    2. Tree->setObjectName("DirView");
    3. Tree->setGeometry(20, 90, 435, 120);
    4.  
    5. QStringList dirsList;
    6. dirsList << "/usr" << "/opt" << "/home";
    7.  
    8. QStandardItemModel dirs( 3, 1 );
    9. Tree->setModel(&dirs);
    10. for ( int i = 0; i < dirs.rowCount(); ++i )
    11. { QStandardItem *item = new QStandardItem(QString::number(i));
    12. item->setCheckable( true );
    13. dirs.setItem( i, item );
    14. }
    To copy to clipboard, switch view to plain text mode 

    but the treeview now just is empty?
    what did i do wrong?

    thanks,

    toby
    Last edited by t0bias; 30th August 2008 at 21:10. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView is empty

    You create your model on the stack and it gets destroyed when it goes out of scope. Create it on the heap.

  3. The following user says thank you to jacek for this useful post:

    t0bias (31st August 2008)

  4. #3
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeView is empty

    thanks, that made it work!

Similar Threads

  1. QTreeView repaint
    By graeme in forum Qt Programming
    Replies: 17
    Last Post: 13th March 2012, 13:27
  2. QDirModel and QTreeView cut and paste
    By Micawber in forum Qt Programming
    Replies: 4
    Last Post: 28th May 2008, 20:16
  3. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  4. remove directory empty or not empty
    By raphaelf in forum Newbie
    Replies: 12
    Last Post: 27th October 2006, 07:30
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24

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.