Results 1 to 2 of 2

Thread: Problem with updating QTreeView with QAbstractITemModel

  1. #1
    Join Date
    Apr 2021

    Default Problem with updating QTreeView with QAbstractITemModel

    Hi everyone,

    I am working on the "Simple Tree Model" example.

    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?

    Qt Code:
    1. #include <QMainWindow>
    2. #include <QtGui>
    3. #include <QTreeView>
    4. #include "treemodel.h"
    5. #include "mainwindow.h"
    6. #include "ui_mainwindow.h"
    8. MainWindow::MainWindow(QWidget *parent)
    9. : QMainWindow(parent)
    10. , ui(new Ui::MainWindow)
    11. {
    12. ui->setupUi(this);
    13. QFile file("/hdd2/users/mohsinali/Inc_Training_Utility/0.sampleFiles/Default.txt");
    15. TreeModel model(file.readAll());
    16. file.close();
    17. ui->treeView->setModel(&model);
    18. ui->treeView->setWindowTitle("Simple Tree Model");
    19. setCentralWidget(ui->treeView);
    20. }
    To copy to clipboard, switch view to plain text mode 


  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 864 Times in 851 Posts
    Qt products

    Default Re: Problem with updating QTreeView with QAbstractITemModel

    Line 15 - think about what happens to this variable that you create on the stack when the MainWindow constructor exits.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    Mohsin (28th April 2021)

Similar Threads

  1. Updating QAbstractItemModel with new records
    By psih128 in forum Qt Programming
    Replies: 0
    Last Post: 10th May 2010, 02:02
  2. QTreeView with QAbstractItemModel
    By Fletcher in forum Qt Programming
    Replies: 4
    Last Post: 11th December 2009, 00:02
  3. Need help Updating QTreeView model (QAbstractItemModel)
    By iraytrace in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2009, 23:49
  4. Creating a QAbstractItemModel for QTreeView
    By hbill in forum Qt Programming
    Replies: 13
    Last Post: 14th August 2008, 17:01
  5. Need help with QTreeView/QAbstractItemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th August 2006, 16:09

Tags for this Thread


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.