Results 1 to 5 of 5

Thread: QTreeView Not displaying

  1. #1

    Default QTreeView Not displaying

    Hey guys/gals,

    Hoping i could get some help. I'm new to QT and I am having a problem with getting the treeview to work right. I copied the treeitem and treemodel files from the simpletreemodel example in qtcreator. I imported the example data file as a resource into my project. When I debug the project, the model looks like it was created fine and the model gets loaded into the treeview. i can even look at the model by accessing it through the treeview itself. The problem is no data is displayed at all. Just blank. I feel like I must be missing something real obvious

    here is the code i call to load in the model

    QFile file(":/resources/default.txt");
    bool test = file.open(QIODevice::ReadOnly);
    TreeModel model(file.readAll());
    file.close();
    ui->navigationTreeView->setModel(&model);
    ui->navigationTreeView->show();

    any help would be appreciated

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTreeView Not displaying

    Can the model actually read the file? But you say the model was created fine, so I guess it can.

    Did you change the code after copying it? If so, please post the code.

  3. #3

    Default Re: QTreeView Not displaying

    I copied the itemtree and itemmodel headers and source exactly.

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QTreeView Not displaying

    You need to create your model on the heap:
    Qt Code:
    1. TreeModel *model = new TreeModel(file.readAll());
    2. file.close();
    3. ui->navigationTreeView->setModel(model);
    4. //ui->navigationTreeView->show();
    To copy to clipboard, switch view to plain text mode 

  5. #5

    Default Re: QTreeView Not displaying

    That worked perfectly. Thank you!

Similar Threads

  1. Displaying QDomDocument
    By champ in forum Newbie
    Replies: 0
    Last Post: 22nd June 2010, 19:47
  2. displaying .gif
    By sven-kt in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2009, 12:00
  3. Process the display data before displaying in QTreeView
    By babu198649 in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2009, 05:21
  4. Drop indicator not displaying with QTreeView. Need help
    By bigchiller in forum Qt Programming
    Replies: 12
    Last Post: 12th March 2008, 11:38
  5. GUI not displaying
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2007, 21:28

Tags for this Thread

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.