[Qt-interest] Question on QAbstractItemView::setModel

Stephen Kelly steveire at gmail.com
Thu Dec 30 17:41:28 CET 2010


Mathieu Malaterre wrote:

> void MainWindow::slot1()
> {
> QFile file("/tmp/default.txt");
> file.open(QIODevice::ReadOnly);
> 
> TreeModel model(file.readAll());
> file.close();
> ui->treeView->setModel(&model);
> ui->treeView->update();
> 
> // update a text label just to check:
> ui->label->setText( "coucou");
> }
> 

You need to create the model on the heap:

TreeModel *model = new TreeModel(file.readAll(), this);

ui->treeView->setModel(model);




More information about the Qt-interest-old mailing list