[Qt-interest] Question on QAbstractItemView::setModel
Mathieu Malaterre
mathieu.malaterre at gmail.com
Thu Dec 30 18:00:42 CET 2010
On Thu, Dec 30, 2010 at 5:41 PM, Stephen Kelly <steveire at gmail.com> wrote:
> 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);
Work like a charm :)
Thanks !
--
Mathieu
More information about the Qt-interest-old
mailing list