PDA

View Full Version : QTreeView Not displaying



meadmaker
27th August 2010, 04:49
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

tbscope
27th August 2010, 05:42
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.

meadmaker
28th August 2010, 01:48
I copied the itemtree and itemmodel headers and source exactly.

norobro
28th August 2010, 02:25
You need to create your model on the heap:
TreeModel *model = new TreeModel(file.readAll());
file.close();
ui->navigationTreeView->setModel(model);
//ui->navigationTreeView->show();

meadmaker
28th August 2010, 05:19
That worked perfectly. Thank you!