PDA

View Full Version : Problem with updating QTreeView with QAbstractITemModel



Mohsin
27th April 2021, 09:47
Hi everyone,


I am working on the "Simple Tree Model" example. https://het.as.utexas.edu/HET/Software/html/itemviews-simpletreemodel.html

However, the data in my QTreeView is not being updated.

If somebody can tell that where I am making a mistake that would be great?




#include <QMainWindow>
#include <QtGui>
#include <QTreeView>
#include "treemodel.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFile file("/hdd2/users/mohsinali/Inc_Training_Utility/0.sampleFiles/Default.txt");
file.open(QIODevice::ReadOnly);
TreeModel model(file.readAll());
file.close();
ui->treeView->setModel(&model);
ui->treeView->setWindowTitle("Simple Tree Model");
setCentralWidget(ui->treeView);
}

13632

d_stranz
27th April 2021, 16:58
Line 15 - think about what happens to this variable that you create on the stack when the MainWindow constructor exits.